mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
Merge remote-tracking branch 'LCTT/master'
This commit is contained in:
commit
546a105910
@ -0,0 +1,59 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (chenmu-kk)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12768-1.html)
|
||||
[#]: subject: (My first contribution to open source: Making a decision)
|
||||
[#]: via: (https://opensource.com/article/19/11/my-first-open-source-contribution-mistake-decisions)
|
||||
[#]: author: (Galen Corey https://opensource.com/users/galenemco)
|
||||
|
||||
我的第一次开源贡献:做出决定
|
||||
======
|
||||
|
||||
> 一位新的开源贡献者告诉你如何加入到开源项目中。
|
||||
|
||||
![](https://img.linux.net.cn/data/attachment/album/202010/30/112350rh0xwp1x1y6awehn.jpg)
|
||||
|
||||
先前,我把我的第一次开源贡献的拖延归咎于[冒牌综合症][2]。但还有一个我无法忽视的因素:我做出决定太艰难了。在[成千上百万][3]的开源项目中选择时,选择一个要做贡献的项目是难以抉择的。如此重负,以至于我常常不得不关掉我的笔记本去思考:“或许我改天再做吧”。
|
||||
|
||||
错误之二是让我对做出决定的恐惧妨碍了我做出第一次贡献。在理想世界里,也许开始我的开源之旅时,心中就已经有了一个真正关心和想去做的具体项目,但我有的只是总得为开源项目做出贡献的模糊目标。对于那些处于同一处境的人来说,这儿有一些帮助我挑选出合适的项目(或者至少是一个好的项目)来做贡献的策略。
|
||||
|
||||
### 经常使用的工具
|
||||
|
||||
一开始,我不认为有必要将自己局限于已经熟悉的工具或项目。有一些项目我之前从未使用过,但由于它们的社区很活跃,或者它们解决的问题很有趣,因此看起来很有吸引力。
|
||||
|
||||
但是,考虑我投入到这个项目中的时间有限,我决定继续投入到我了解的工具上去。要了解工具需求,你需要熟悉它的工作方式。如果你想为自己不熟悉的项目做贡献,则需要完成一个额外的步骤来了解代码的功能和目标。这个额外的工作量可能是有趣且值得的,但也会使你的工作时间加倍。因为我的目标主要是贡献,投入到我了解的工具上是缩小范围的很好方式。回馈一个你认为有用的项目也是有意义的。
|
||||
|
||||
### 活跃而友好的社区
|
||||
|
||||
在选择项目的时候,我希望在那里有人会审查我写的代码才会觉得有信心。当然,我也希望审核我代码的人是个和善的人。毕竟,把你的作品放在那里接受公众监督是很可怕的。虽然我对建设性的反馈持开放态度,但开发者社区中的一些有毒角落是我希望避免的。
|
||||
|
||||
为了评估我将要加入的社区,我查看了我正在考虑加入的仓库的<ruby>议题<rt>issue</rt></ruby>部分。我要查看核心团队中是否有人定期回复。更重要的是,我试着确保没有人在评论中互相诋毁(这在议题讨论中是很常见的)。我还留意了那些有行为准则的项目,概述了什么是适当的和不适当的在线互动行为。
|
||||
|
||||
### 明确的贡献准则
|
||||
|
||||
因为这是我第一次为开源项目做出贡献,在此过程中我有很多问题。一些项目社区在流程的文档记录方面做的很好,可以用来指导挑选其中的议题并发起拉取请求。 [Gatsby][4] 是这种做法的典范,尽管那时我没有选择它们,因为在此之前我从未使用过该产品。
|
||||
|
||||
这种清晰的文档帮助我们缓解了一些不知如何去做的不安全感。它也给了我希望:项目对新的贡献者是开放的,并且会花时间来查看我的工作。除了贡献准则外,我还查看了议题部分,看看这个项目是否使用了“<ruby>第一个好议题<rt>good first issue</rt></ruby>”标志。这是该项目对初学者开放的另一个迹象(并可以帮助你学会要做什么)。
|
||||
|
||||
### 总结
|
||||
|
||||
如果你还没有计划好选择一个项目,那么选择合适的领域进行你的第一个开源贡献更加可行。列出一系列标准可以帮助自己缩减选择范围,并为自己的第一个拉取请求找到一个好的项目。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/my-first-open-source-contribution-mistake-decisions
|
||||
|
||||
作者:[Galen Corey][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[chenmu-kk](https://github.com/chenmu-kk)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/galenemco
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh (Lightbulb)
|
||||
[2]: https://opensource.com/article/19/10/my-first-open-source-contribution-mistakes
|
||||
[3]: https://github.blog/2018-02-08-open-source-project-trends-for-2018/
|
||||
[4]: https://www.gatsbyjs.org/contributing/
|
@ -0,0 +1,389 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Improve your database knowledge with this MariaDB and MySQL cheat sheet)
|
||||
[#]: via: (https://opensource.com/article/20/10/mariadb-mysql-cheat-sheet)
|
||||
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
|
||||
|
||||
Improve your database knowledge with this MariaDB and MySQL cheat sheet
|
||||
======
|
||||
Read this article and download our free cheat sheet to get started using
|
||||
an open source database.
|
||||
![Cheat Sheet cover image][1]
|
||||
|
||||
When you're writing an application or configuring one for a server, eventually, you will need to store persistent information. Sometimes, a configuration file, such as an INI or [YAML][2] file will do. Other times, a custom file format designed in XML or JSON or similar is better.
|
||||
|
||||
But sometimes you need something that can validate input, search through information quickly, make connections between related data, and generally handle your users' work adeptly. That's what a database is designed to do, and [MariaDB][3] (a fork of [MySQL][4] by some of its original developers) is a great option. I use MariaDB in this article, but the information applies equally to MySQL.
|
||||
|
||||
It's common to interact with a database through programming languages. For this reason, there are [SQL][5] libraries for Java, Python, Lua, PHP, Ruby, C++, and many others. However, before using these libraries, it helps to have an understanding of what's happening with the database engine and why your choice of database is significant. This article introduces MariaDB and the `mysql` command to familiarize you with the basics of how a database handles data.
|
||||
|
||||
If you don't have MariaDB yet, follow the instructions in my article about [installing MariaDB on Linux][6]. If you're not on Linux, use the instructions provided on the MariaDB [download page][7].
|
||||
|
||||
### Interact with MariaDB
|
||||
|
||||
You can interact with MariaDB using the `mysql` command. First, verify that your server is up and running using the `ping` subcommand, entering your MariaDB password when prompted:
|
||||
|
||||
|
||||
```
|
||||
$ mysqladmin -u root -p ping
|
||||
Enter password:
|
||||
mysqld is alive
|
||||
```
|
||||
|
||||
To make exploring SQL easy, open an interactive MariaDB session:
|
||||
|
||||
|
||||
```
|
||||
$ mysql -u root -p
|
||||
Enter password:
|
||||
Welcome to the MariaDB monitor.
|
||||
Commands end with ; or \g.
|
||||
[...]
|
||||
Type 'help;' or '\h' for help.
|
||||
Type '\c' to clear the current input statement.
|
||||
|
||||
MariaDB [(none)]>
|
||||
```
|
||||
|
||||
This places you in a MariaDB subshell, and your prompt is now a MariaDB prompt. Your usual Bash commands don't work here. You must use MariaDB commands. To see a list of MariaDB commands, type `help` (or just `?`). These are administrative commands for your MariaDB shell, so they're useful for customizing your shell, but they aren't part of the SQL language.
|
||||
|
||||
### Learn SQL basics
|
||||
|
||||
The [Structured Query Language (SQL)][8] is named after what it provides: a method to inquire about the contents of a database in a predictable and consistent syntax in order to receive useful results. SQL reads a lot like an ordinary English sentence, if a little robotic. For instance, if you've signed into a database server and you need to understand what you have to work with, type `SHOW DATABASES;` and press Enter for the results.
|
||||
|
||||
SQL commands are terminated with a semicolon. If you forget the semicolon, MariaDB assumes you want to continue your query on the next line, where you can either do so or terminate the query with a semicolon.
|
||||
|
||||
|
||||
```
|
||||
MariaDB [(NONE)]> SHOW DATABASES;
|
||||
+--------------------+
|
||||
| DATABASE |
|
||||
+--------------------+
|
||||
| information_schema |
|
||||
| mysql |
|
||||
| performance_schema |
|
||||
| test |
|
||||
+--------------------+
|
||||
4 ROWS IN SET (0.000 sec)
|
||||
```
|
||||
|
||||
This shows there are four databases present: information_schema, mysql, performance_schema, and test. To issue queries to a database, you must select which database you want MariaDB to use. This is done with the MariaDB command `use`. Once you choose a database, your MariaDB prompt changes to reflect the active database.
|
||||
|
||||
|
||||
```
|
||||
MariaDB [(NONE)]> USE test;
|
||||
MariaDB [(test)]>
|
||||
```
|
||||
|
||||
#### Show database tables
|
||||
|
||||
Databases contain _tables_, which can be visualized in the same way a spreadsheet is: as a series of rows (called _records_ in a database) and columns. The intersection of a row and a column is called a _field_.
|
||||
|
||||
To see the tables available in a database (you can think of them as tabs in a multi-sheet spreadsheet), use the SQL keyword `SHOW` again:
|
||||
|
||||
|
||||
```
|
||||
MariaDB [(test)]> SHOW TABLES;
|
||||
empty SET
|
||||
```
|
||||
|
||||
The `test` database doesn't have much to look at, so use the `use` command to switch to the `mysql` database.
|
||||
|
||||
|
||||
```
|
||||
MariaDB [(test)]> USE mysql;
|
||||
MariaDB [(mysql)]> SHOW TABLES;
|
||||
|
||||
+---------------------------+
|
||||
| Tables_in_mysql |
|
||||
+---------------------------+
|
||||
| column_stats |
|
||||
| columns_priv |
|
||||
| db |
|
||||
[...]
|
||||
| time_zone_transition_type |
|
||||
| transaction_registry |
|
||||
| USER |
|
||||
+---------------------------+
|
||||
31 ROWS IN SET (0.000 sec)
|
||||
```
|
||||
|
||||
There are a lot more tables in this database! The `mysql` database is the system management database for this MariaDB instance. It contains important data, including an entire user structure to manage database privileges. It's an important database, and you don't always have to interact with it directly, but it's not uncommon to manipulate it in SQL scripts. It's also useful to understand the `mysql` database when you're learning MariaDB because it can help demonstrate some basic SQL commands.
|
||||
|
||||
#### Examine a table
|
||||
|
||||
The last table listed in this instance's `mysql` database is titled `user`. This table contains data about users permitted to access the database. Right now, there's only a root user, but you can add other users with varying privileges to control whether each user can view, update, or create data. To get an idea of all the attributes a MariaDB user can have, you can view column headers in a table:
|
||||
|
||||
|
||||
```
|
||||
> SHOW COLUMNS IN USER;
|
||||
MariaDB [mysql]> SHOW COLUMNS IN USER;
|
||||
+-------------+---------------+------+-----+----------+
|
||||
| FIELD | TYPE | NULL | KEY | DEFAULT |
|
||||
+-------------+---------------+------+-----+----------+
|
||||
| Host | CHAR(60) | NO | PRI | |
|
||||
| USER | CHAR(80) | NO | PRI | |
|
||||
| Password | CHAR(41) | NO | | |
|
||||
| Select_priv | enum('N','Y') | NO | | N |
|
||||
| Insert_priv | enum('N','Y') | NO | | N |
|
||||
| Update_priv | enum('N','Y') | NO | | N |
|
||||
| Delete_priv | enum('N','Y') | NO | | N |
|
||||
| Create_priv | enum('N','Y') | NO | | N |
|
||||
| Drop_priv | enum('N','Y') | NO | | N |
|
||||
[...]
|
||||
47 ROWS IN SET (0.001 sec)
|
||||
```
|
||||
|
||||
#### Create a new user
|
||||
|
||||
Whether you need help from a fellow human to administer a database or you're setting up a database for a computer to use (for example, in a WordPress, Drupal, or Joomla installation), it's common to need an extra user account within MariaDB. You can create a MariaDB user either by adding it to the `user` table in the `mysql` database, or you can use the SQL keyword `CREATE` to prompt MariaDB to do it for you. The latter features some helper functions so that you don't have to generate all the information manually:
|
||||
|
||||
|
||||
```
|
||||
`> CREATE USER 'tux'@'localhost' IDENTIFIED BY 'really_secure_password';`
|
||||
```
|
||||
|
||||
#### View table fields
|
||||
|
||||
You can view fields and values in a database table with the `SELECT` keyword. In this example, you created a user called `tux`, so select the columns in the `user` table:
|
||||
|
||||
|
||||
```
|
||||
> SELECT USER,host FROM USER;
|
||||
+------+------------+
|
||||
| USER | host |
|
||||
+------+------------+
|
||||
| root | localhost |
|
||||
[...]
|
||||
| tux | localhost |
|
||||
+------+------------+
|
||||
7 ROWS IN SET (0.000 sec)
|
||||
```
|
||||
|
||||
#### Grant privileges to a user
|
||||
|
||||
By looking at the column listing on the `user` table, you can explore a user's status. For instance, the new user `tux` doesn't have permission to do anything with the database. Using the `WHERE` statement, you can view only the record for `tux`:
|
||||
|
||||
|
||||
```
|
||||
> SELECT USER,select_priv,insert_priv,update_priv FROM USER WHERE USER='tux';
|
||||
+------+-------------+-------------+-------------+
|
||||
| USER | select_priv | insert_priv | update_priv |
|
||||
+------+-------------+-------------+-------------+
|
||||
| tux | N | N | N |
|
||||
+------+-------------+-------------+-------------+
|
||||
```
|
||||
|
||||
Use the `GRANT` command to modify user permissions:
|
||||
|
||||
|
||||
```
|
||||
> GRANT SELECT ON *.* TO 'tux'@'localhost';
|
||||
> FLUSH PRIVILEGES;
|
||||
```
|
||||
|
||||
Verify your change:
|
||||
|
||||
|
||||
```
|
||||
> SELECT USER,select_priv,insert_priv,update_priv FROM USER WHERE USER='tux';
|
||||
+------+-------------+-------------+-------------+
|
||||
| USER | select_priv | insert_priv | update_priv |
|
||||
+------+-------------+-------------+-------------+
|
||||
| tux | Y | N | N |
|
||||
+------+-------------+-------------+-------------+
|
||||
```
|
||||
|
||||
User `tux` now has privileges to select records from all tables.
|
||||
|
||||
### Create a custom database
|
||||
|
||||
So far, you've interacted just with the default databases. Most people rarely interact much with the default databases outside of user management. Usually, you create a database and populate it with tables full of custom data.
|
||||
|
||||
#### Create a MariaDB database
|
||||
|
||||
You may already be able to guess how to create a new database in MariaDB. It's a lot like creating a new user:
|
||||
|
||||
|
||||
```
|
||||
> CREATE DATABASE example;
|
||||
Query OK, 1 ROW affected (0.000 sec)
|
||||
> SHOW DATABASES;
|
||||
+--------------------+
|
||||
| DATABASE |
|
||||
+--------------------+
|
||||
| example |
|
||||
[...]
|
||||
```
|
||||
|
||||
Make this new database your active one with the `use` command:
|
||||
|
||||
|
||||
```
|
||||
`> USE example;`
|
||||
```
|
||||
|
||||
#### Create a table
|
||||
|
||||
Creating a table is more complex than creating a database because you must define column headings. MariaDB provides many convenience functions for you to use when creating columns, including data type definitions, automatic incrementing options, constraints to avoid empty values, automated timestamps, and more.
|
||||
|
||||
Here's a simple table to describe a set of users:
|
||||
|
||||
|
||||
```
|
||||
> CREATE TABLE IF NOT EXISTS member (
|
||||
-> id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
-> name VARCHAR(128) NOT NULL,
|
||||
-> startdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
|
||||
Query OK, 0 ROWS affected (0.030 sec)
|
||||
```
|
||||
|
||||
This table provides a unique identifier to each row by using an auto-increment function. It contains a field for a user's name, which cannot be empty (or `null`), and generates a timestamp when the record is created.
|
||||
|
||||
Populate this table with some sample data using the `INSERT` SQL keyword:
|
||||
|
||||
|
||||
```
|
||||
> INSERT INTO member (name) VALUES ('Alice');
|
||||
Query OK, 1 ROW affected (0.011 sec)
|
||||
> INSERT INTO member (name) VALUES ('Bob');
|
||||
Query OK, 1 ROW affected (0.011 sec)
|
||||
> INSERT INTO member (name) VALUES ('Carol');
|
||||
Query OK, 1 ROW affected (0.011 sec)
|
||||
> INSERT INTO member (name) VALUES ('David');
|
||||
Query OK, 1 ROW affected (0.011 sec)
|
||||
```
|
||||
|
||||
Verify the data in the table:
|
||||
|
||||
|
||||
```
|
||||
> SELECT * FROM member;
|
||||
+----+-------+---------------------+
|
||||
| id | name | startdate |
|
||||
+----+-------+---------------------+
|
||||
| 1 | Alice | 2020-10-03 15:25:06 |
|
||||
| 2 | Bob | 2020-10-03 15:26:43 |
|
||||
| 3 | Carol | 2020-10-03 15:26:46 |
|
||||
| 4 | David | 2020-10-03 15:26:51 |
|
||||
+----+-------+---------------------+
|
||||
4 ROWS IN SET (0.000 sec)
|
||||
```
|
||||
|
||||
#### Add multiple rows at once
|
||||
|
||||
Now create a second table:
|
||||
|
||||
|
||||
```
|
||||
> CREATE TABLE IF NOT EXISTS linux (
|
||||
-> id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
-> distro VARCHAR(128) NOT NULL,
|
||||
Query OK, 0 ROWS affected (0.030 sec)
|
||||
```
|
||||
|
||||
Populate it with some sample data, this time using a little `VALUES` shortcut so you can add multiple rows in one command. The `VALUES` keyword expects a list in parentheses, but it can take multiple lists separated by commas:
|
||||
|
||||
|
||||
```
|
||||
> INSERT INTO linux (distro)
|
||||
-> VALUES ('Slackware'), ('RHEL'),('Fedora'),('Debian');
|
||||
Query OK, 4 ROWS affected (0.011 sec)
|
||||
Records: 4 Duplicates: 0 Warnings: 0
|
||||
> SELECT * FROM linux;
|
||||
+----+-----------+
|
||||
| id | distro |
|
||||
+----+-----------+
|
||||
| 1 | Slackware |
|
||||
| 2 | RHEL |
|
||||
| 3 | Fedora |
|
||||
| 4 | Debian |
|
||||
+----+-----------+
|
||||
```
|
||||
|
||||
### Create relationships between tables
|
||||
|
||||
You now have two tables, but there's no relationship between them. They each contain independent data, but you might need to associate a member of the first table to a specific item listed in the second.
|
||||
|
||||
To do that, you can create a new column for the first table that corresponds to something in the second. Because both tables were designed with unique identifiers (the auto-incrementing `id` field), the easiest way to connect them is to use the `id` field of one as a selector for the other.
|
||||
|
||||
Create a new column in the first table to represent a value in the second table:
|
||||
|
||||
|
||||
```
|
||||
> ALTER TABLE member ADD COLUMN (os INT);
|
||||
Query OK, 0 ROWS affected (0.012 sec)
|
||||
Records: 0 Duplicates: 0 Warnings: 0
|
||||
> DESCRIBE member;
|
||||
DESCRIBE member;
|
||||
+-----------+--------------+------+-----+---------+------+
|
||||
| FIELD | TYPE | NULL | KEY | DEFAULT | Extra|
|
||||
+-----------+--------------+------+-----+---------+------+
|
||||
| id | INT(11) | NO | PRI | NULL | auto_|
|
||||
| name | VARCHAR(128) | NO | | NULL | |
|
||||
| startdate | TIMESTAMP | NO | | cur[...]| |
|
||||
| os | INT(11) | YES | | NULL | |
|
||||
+-----------+--------------+------+-----+---------+------+
|
||||
```
|
||||
|
||||
Using the unique IDs of the `linux` table, assign a distribution to each member. Because the records already exist, use the `UPDATE` SQL keyword rather than `INSERT`. Specifically, you want to select one row and then update the value of one column. Syntactically, this is expressed a little in reverse, with the update happening first and the selection matching last:
|
||||
|
||||
|
||||
```
|
||||
> UPDATE member SET os=1 WHERE name='Alice';
|
||||
Query OK, 1 ROW affected (0.007 sec)
|
||||
ROWS matched: 1 Changed: 1 Warnings: 0
|
||||
```
|
||||
|
||||
Repeat this process for the other names in the `member` table to populate it with data. For variety, assign three different distributions across the four rows (doubling up on one).
|
||||
|
||||
#### Join tables
|
||||
|
||||
Now that these two tables relate to one another, you can use SQL to display the associated data. There are many kinds of joins in databases, and you can try them all once you know the basics. Here's a basic join to correlate the values found in the `os` field of the `member` table to the `id` field of the `linux` table:
|
||||
|
||||
|
||||
```
|
||||
SELECT * FROM member JOIN linux ON member.os=linux.id;
|
||||
+----+-------+---------------------+------+----+-----------+
|
||||
| id | name | startdate | os | id | distro |
|
||||
+----+-------+---------------------+------+----+-----------+
|
||||
| 1 | Alice | 2020-10-03 15:25:06 | 1 | 1 | Slackware |
|
||||
| 2 | Bob | 2020-10-03 15:26:43 | 3 | 3 | Fedora |
|
||||
| 4 | David | 2020-10-03 15:26:51 | 3 | 3 | Fedora |
|
||||
| 3 | Carol | 2020-10-03 15:26:46 | 4 | 4 | Debian |
|
||||
+----+-------+---------------------+------+----+-----------+
|
||||
4 ROWS IN SET (0.000 sec)
|
||||
```
|
||||
|
||||
The `os` and `id` fields form the join.
|
||||
|
||||
In a graphical application, you can imagine that the `os` field might be set by a drop-down menu, the values for which are drawn from the contents of the `distro` field of the `linux` table. By using separate tables for unique but related sets of data, you ensure the consistency and validity of data, and thanks to SQL, you can associate them dynamically later.
|
||||
|
||||
### [Download the MariaDB and MySQL cheat sheet][9]
|
||||
|
||||
MariaDB is an enterprise-grade database. It's designed and proven to be a robust, powerful, and fast database engine. Learning it is a great step toward using it to do things like managing web applications or programming language libraries. As a quick reference when you're using MariaDB, [download our MariaDB and MySQL cheat sheet][9].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/mariadb-mysql-cheat-sheet
|
||||
|
||||
作者:[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/coverimage_cheat_sheet.png?itok=lYkNKieP (Cheat Sheet cover image)
|
||||
[2]: https://www.redhat.com/sysadmin/yaml-tips
|
||||
[3]: https://mariadb.org/
|
||||
[4]: https://www.mysql.com/
|
||||
[5]: https://en.wikipedia.org/wiki/SQL
|
||||
[6]: https://opensource.com/article/20/10/install-mariadb-and-mysql-linux
|
||||
[7]: https://mariadb.org/download
|
||||
[8]: https://publications.opengroup.org/c449
|
||||
[9]: https://opensource.com/downloads/mariadb-mysql-cheat-sheet
|
@ -0,0 +1,369 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (Managing resources with cgroups in systemd)
|
||||
[#]: via: (https://opensource.com/article/20/10/cgroups)
|
||||
[#]: author: (David Both https://opensource.com/users/dboth)
|
||||
|
||||
Managing resources with cgroups in systemd
|
||||
======
|
||||
Cgroups manage resources per application rather than by the individual
|
||||
processes that make up an application.
|
||||
![Business woman on laptop sitting in front of window][1]
|
||||
|
||||
There is little more frustrating to me as a sysadmin than unexpectedly running out of a computing resource. On more than one occasion, I have filled all available disk space in a partition, run out of RAM, and not had enough CPU time to perform my tasks in a reasonable amount of time. Resource management is one of the most important tasks that sysadmins do.
|
||||
|
||||
The point of resource management is to ensure that all processes have relatively equal access to the system resources they need. Resource management also involves ensuring that RAM, hard drive space, and CPU capacity are added when necessary or rationed when that is not possible. In addition, users who hog system resources, whether intentionally or accidentally, should be prevented from doing so.
|
||||
|
||||
There are tools that enable sysadmins to monitor and manage various system resources. For example, [top][2] and similar tools allow you to monitor the use of memory, I/O, storage (disk, SSD, etc.), network, swap space, CPU usage, and more. These tools, particularly those that are CPU-centric, are mostly based on the paradigm that the running process is the unit of control. At best, they provide a way to adjust the nice number–and through that, the priority—or to kill a running process. (For information about nice numbers, see [_Monitoring Linux and Windows hosts with Glances_][3].)
|
||||
|
||||
Other tools based on traditional resource management in a SystemV environment are managed by the `/etc/security/limits.conf` file and the local configuration files located in the `/etc/security/limits.d` directory. Resources can be limited in a fairly crude but useful manner by user or group. Resources that can be managed include various aspects of RAM, total CPU time per day, total amount of data, priority, nice number, number of concurrent logins, number of processes, maximum file size, and more.
|
||||
|
||||
### Using cgroups for process management
|
||||
|
||||
One major difference between [systemd and SystemV][4] is how they handle processes. SystemV treats each process as an entity unto itself. systemd collects related processes into control groups, called [cgroups][5] (short for control groups), and manages system resources for the cgroup as a whole. This means resources can be managed per application rather than by the individual processes that make up an application.
|
||||
|
||||
The control units for cgroups are called slice units. Slices are a conceptualization that allows systemd to order processes in a tree format for ease of management.
|
||||
|
||||
### Viewing cgroups
|
||||
|
||||
I'll start with some commands that allow you to view various types of information about cgroups. The `systemctl status <service>` command displays slice information about a specified service, including its slice. This example shows the `at` daemon:
|
||||
|
||||
|
||||
```
|
||||
[root@testvm1 ~]# systemctl status atd.service
|
||||
● atd.service - Deferred execution scheduler
|
||||
Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled)
|
||||
Active: active (running) since Wed 2020-09-23 12:18:24 EDT; 1 day 3h ago
|
||||
Docs: man:atd(8)
|
||||
Main PID: 1010 (atd)
|
||||
Tasks: 1 (limit: 14760)
|
||||
Memory: 440.0K
|
||||
CPU: 5ms
|
||||
CGroup: /system.slice/atd.service
|
||||
└─1010 /usr/sbin/atd -f
|
||||
|
||||
Sep 23 12:18:24 testvm1.both.org systemd[1]: Started Deferred execution scheduler.
|
||||
[root@testvm1 ~]#
|
||||
```
|
||||
|
||||
This is an excellent example of one reason that I find systemd more usable than SystemV and the old init program. There is so much more information here than SystemV could provide. The cgroup entry includes the hierarchical structure where the `system.slice` is systemd (PID 1), and the `atd.service` is one level below and part of the `system.slice`. The second line of the cgroup entry also shows the process ID (PID) and the command used to start the daemon.
|
||||
|
||||
The `systemctl` command shows multiple cgroup entries. The `--all` option shows all slices, including those that are not currently active:
|
||||
|
||||
|
||||
```
|
||||
[root@testvm1 ~]# systemctl -t slice --all
|
||||
UNIT LOAD ACTIVE SUB DESCRIPTION
|
||||
-.slice loaded active active Root Slice
|
||||
system-getty.slice loaded active active system-getty.slice
|
||||
system-lvm2\x2dpvscan.slice loaded active active system-lvm2\x2dpvscan.slice
|
||||
system-modprobe.slice loaded active active system-modprobe.slice
|
||||
system-sshd\x2dkeygen.slice loaded active active system-sshd\x2dkeygen.slice
|
||||
system-systemd\x2dcoredump.slice loaded inactive dead system-systemd\x2dcoredump.slice
|
||||
system-systemd\x2dfsck.slice loaded active active system-systemd\x2dfsck.slice
|
||||
system.slice loaded active active System Slice
|
||||
user-0.slice loaded active active User Slice of UID 0
|
||||
user-1000.slice loaded active active User Slice of UID 1000
|
||||
user.slice loaded active active User and Session Slice
|
||||
|
||||
LOAD = Reflects whether the unit definition was properly loaded.
|
||||
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
|
||||
SUB = The low-level unit activation state, values depend on unit type.
|
||||
|
||||
11 loaded units listed.
|
||||
To show all installed unit files use 'systemctl list-unit-files'.
|
||||
[root@testvm1 ~]#
|
||||
```
|
||||
|
||||
The first thing to notice about this data is that it shows user slices for UIDs 0 (root) and 1000, which is my user login. This shows only the slices and not the services that are part of each slice. This data shows that a slice is created for each user at the time they log in. This can provide a way to manage all of a user's tasks as a single cgroup entity.
|
||||
|
||||
### Explore the cgroup hierarchy
|
||||
|
||||
All is well and good so far, but cgroups are hierarchical, and all of the service units run as members of one of the cgroups. Viewing that hierarchy is easy and uses one old command and one new one that is part of systemd.
|
||||
|
||||
The `ps` command can be used to map the processes and their locations in the cgroup hierarchy. Note that it is necessary to specify the desired data columns when using the `ps` command. I significantly reduced the volume of output from this command below, but I tried to leave enough so you can get a feel for what you might find on your systems:
|
||||
|
||||
|
||||
```
|
||||
[root@testvm1 ~]# ps xawf -eo pid,user,cgroup,args
|
||||
PID USER CGROUP COMMAND
|
||||
2 root - [kthreadd]
|
||||
3 root - \\_ [rcu_gp]
|
||||
4 root - \\_ [rcu_par_gp]
|
||||
6 root - \\_ [kworker/0:0H-kblockd]
|
||||
9 root - \\_ [mm_percpu_wq]
|
||||
10 root - \\_ [ksoftirqd/0]
|
||||
11 root - \\_ [rcu_sched]
|
||||
12 root - \\_ [migration/0]
|
||||
13 root - \\_ [cpuhp/0]
|
||||
14 root - \\_ [cpuhp/1]
|
||||
<SNIP>
|
||||
625406 root - \\_ [kworker/3:0-ata_sff]
|
||||
625409 root - \\_ [kworker/u8:0-events_unbound]
|
||||
1 root 0::/init.scope /usr/lib/systemd/systemd --switched-root --system --deserialize 30
|
||||
588 root 0::/system.slice/systemd-jo /usr/lib/systemd/systemd-journald
|
||||
599 root 0::/system.slice/systemd-ud /usr/lib/systemd/systemd-udevd
|
||||
741 root 0::/system.slice/auditd.ser /sbin/auditd
|
||||
743 root 0::/system.slice/auditd.ser \\_ /usr/sbin/sedispatch
|
||||
764 root 0::/system.slice/ModemManag /usr/sbin/ModemManager
|
||||
765 root 0::/system.slice/NetworkMan /usr/sbin/NetworkManager --no-daemon
|
||||
767 root 0::/system.slice/irqbalance /usr/sbin/irqbalance --foreground
|
||||
779 root 0::/system.slice/mcelog.ser /usr/sbin/mcelog --ignorenodev --daemon --foreground
|
||||
781 root 0::/system.slice/rngd.servi /sbin/rngd -f
|
||||
782 root 0::/system.slice/rsyslog.se /usr/sbin/rsyslogd -n
|
||||
<SNIP>
|
||||
893 root 0::/system.slice/sshd.servi sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
|
||||
1130 root 0::/user.slice/user-0.slice \\_ sshd: root [priv]
|
||||
1147 root 0::/user.slice/user-0.slice | \\_ sshd: root@pts/0
|
||||
1148 root 0::/user.slice/user-0.slice | \\_ -bash
|
||||
1321 root 0::/user.slice/user-0.slice | \\_ screen
|
||||
1322 root 0::/user.slice/user-0.slice | \\_ SCREEN
|
||||
1323 root 0::/user.slice/user-0.slice | \\_ /bin/bash
|
||||
498801 root 0::/user.slice/user-0.slice | | \\_ man systemd.resource-control
|
||||
498813 root 0::/user.slice/user-0.slice | | \\_ less
|
||||
1351 root 0::/user.slice/user-0.slice | \\_ /bin/bash
|
||||
123293 root 0::/user.slice/user-0.slice | | \\_ man systemd.slice
|
||||
123305 root 0::/user.slice/user-0.slice | | \\_ less
|
||||
1380 root 0::/user.slice/user-0.slice | \\_ /bin/bash
|
||||
625412 root 0::/user.slice/user-0.slice | | \\_ ps xawf -eo pid,user,cgroup,args
|
||||
625413 root 0::/user.slice/user-0.slice | | \\_ less
|
||||
246795 root 0::/user.slice/user-0.slice | \\_ /bin/bash
|
||||
625338 root 0::/user.slice/user-0.slice | \\_ /usr/bin/mc -P /var/tmp/mc-root/mc.pwd.246795
|
||||
625340 root 0::/user.slice/user-0.slice | \\_ bash -rcfile .bashrc
|
||||
1218 root 0::/user.slice/user-1000.sl \\_ sshd: dboth [priv]
|
||||
1233 dboth 0::/user.slice/user-1000.sl \\_ sshd: dboth@pts/1
|
||||
1235 dboth 0::/user.slice/user-1000.sl \\_ -bash
|
||||
<SNIP>
|
||||
1010 root 0::/system.slice/atd.servic /usr/sbin/atd -f
|
||||
1011 root 0::/system.slice/crond.serv /usr/sbin/crond -n
|
||||
1098 root 0::/system.slice/lxdm.servi /usr/sbin/lxdm-binary
|
||||
1106 root 0::/system.slice/lxdm.servi \\_ /usr/libexec/Xorg -background none :0 vt01 -nolisten tcp -novtswitch -auth /var/run/lxdm/lxdm-:0.auth
|
||||
370621 root 0::/user.slice/user-1000.sl \\_ /usr/libexec/lxdm-session
|
||||
370631 dboth 0::/user.slice/user-1000.sl \\_ xfce4-session
|
||||
370841 dboth 0::/user.slice/user-1000.sl \\_ /usr/bin/ssh-agent /bin/sh -c exec -l bash -c "/usr/bin/startxfce4"
|
||||
370911 dboth 0::/user.slice/user-1000.sl \\_ xfwm4 --display :0.0 --sm-client-id 2dead44ab-0b4d-4101-bca4-e6771f4a8ac2
|
||||
370930 dboth 0::/user.slice/user-1000.sl \\_ xfce4-panel --display :0.0 --sm-client-id 2ce38b8ef-86fd-4189-ace5-deec1d0e0952
|
||||
370942 dboth 0::/user.slice/user-1000.sl | \\_ /usr/lib64/xfce4/panel/wrapper-2.0 /usr/lib64/xfce4/panel/plugins/libsystray.so 6 23068680 systr
|
||||
ay Notification Area Area where notification icons appear
|
||||
370943 dboth 0::/user.slice/user-1000.sl | \\_ /usr/lib64/xfce4/panel/wrapper-2.0 /usr/lib64/xfce4/panel/plugins/libpulseaudio-plugin.so 8 2306
|
||||
8681 pulseaudio PulseAudio Plugin Adjust the audio volume of the PulseAudio sound system
|
||||
370944 dboth 0::/user.slice/user-1000.sl | \\_ /usr/lib64/xfce4/panel/wrapper-2.0 /usr/lib64/xfce4/panel/plugins/libxfce4powermanager.so 9 2306
|
||||
8682 power-manager-plugin Power Manager Plugin Display the battery levels of your devices and control the brightness of your display
|
||||
370945 dboth 0::/user.slice/user-1000.sl | \\_ /usr/lib64/xfce4/panel/wrapper-2.0 /usr/lib64/xfce4/panel/plugins/libnotification-plugin.so 10 2
|
||||
3068683 notification-plugin Notification Plugin Notification plugin for the Xfce panel
|
||||
370948 dboth 0::/user.slice/user-1000.sl | \\_ /usr/lib64/xfce4/panel/wrapper-2.0 /usr/lib64/xfce4/panel/plugins/libactions.so 14 23068684 acti
|
||||
ons Action Buttons Log out, lock or other system actions
|
||||
370934 dboth 0::/user.slice/user-1000.sl \\_ Thunar --sm-client-id 2cfc809d8-4e1d-497a-a5c5-6e4fa509c3fb --daemon
|
||||
370939 dboth 0::/user.slice/user-1000.sl \\_ xfdesktop --display :0.0 --sm-client-id 299be0608-4dca-4055-b4d6-55ec6e73a324
|
||||
370962 dboth 0::/user.slice/user-1000.sl \\_ nm-applet
|
||||
<SNIP>
|
||||
```
|
||||
|
||||
You can view the entire hierarchy with the `systemd-cgls` command, which is a bit simpler because it does not require any complex options.
|
||||
|
||||
I have shortened this tree view considerably. as well, but I left enough to give you some idea of the amount of data as well as the types of entries you should see when you do this on your system. I did this on one of my virtual machines, and it is about 200 lines long; the amount of data from my primary workstation is about 250 lines:
|
||||
|
||||
|
||||
```
|
||||
[root@testvm1 ~]# systemd-cgls
|
||||
Control group /:
|
||||
-.slice
|
||||
├─user.slice
|
||||
│ ├─user-0.slice
|
||||
│ │ ├─session-1.scope
|
||||
│ │ │ ├─ 1130 sshd: root [priv]
|
||||
│ │ │ ├─ 1147 sshd: root@pts/0
|
||||
│ │ │ ├─ 1148 -bash
|
||||
│ │ │ ├─ 1321 screen
|
||||
│ │ │ ├─ 1322 SCREEN
|
||||
│ │ │ ├─ 1323 /bin/bash
|
||||
│ │ │ ├─ 1351 /bin/bash
|
||||
│ │ │ ├─ 1380 /bin/bash
|
||||
│ │ │ ├─123293 man systemd.slice
|
||||
│ │ │ ├─123305 less
|
||||
│ │ │ ├─246795 /bin/bash
|
||||
│ │ │ ├─371371 man systemd-cgls
|
||||
│ │ │ ├─371383 less
|
||||
│ │ │ ├─371469 systemd-cgls
|
||||
│ │ │ └─371470 less
|
||||
│ │ └─[user@0.service][6] …
|
||||
│ │ ├─dbus-broker.service
|
||||
│ │ │ ├─1170 /usr/bin/dbus-broker-launch --scope user
|
||||
│ │ │ └─1171 dbus-broker --log 4 --controller 12 --machine-id 3bccd1140fca488187f8a1439c832f07 --max-bytes 100000000000000 --max-fds 25000000000000 --max->
|
||||
│ │ ├─gvfs-daemon.service
|
||||
│ │ │ └─1173 /usr/libexec/gvfsd
|
||||
│ │ └─init.scope
|
||||
│ │ ├─1137 /usr/lib/systemd/systemd --user
|
||||
│ │ └─1138 (sd-pam)
|
||||
│ └─user-1000.slice
|
||||
│ ├─[user@1000.service][7] …
|
||||
│ │ ├─dbus\x2d:1.2\x2dorg.xfce.Xfconf.slice
|
||||
│ │ │ └─dbus-:[1.2-org.xfce.Xfconf@0.service][8]
|
||||
│ │ │ └─370748 /usr/lib64/xfce4/xfconf/xfconfd
|
||||
│ │ ├─dbus\x2d:1.2\x2dca.desrt.dconf.slice
|
||||
│ │ │ └─dbus-:[1.2-ca.desrt.dconf@0.service][9]
|
||||
│ │ │ └─371262 /usr/libexec/dconf-service
|
||||
│ │ ├─dbus-broker.service
|
||||
│ │ │ ├─1260 /usr/bin/dbus-broker-launch --scope user
|
||||
│ │ │ └─1261 dbus-broker --log 4 --controller 11 --machine-id
|
||||
<SNIP>
|
||||
│ │ └─gvfs-mtp-volume-monitor.service
|
||||
│ │ └─370987 /usr/libexec/gvfs-mtp-volume-monitor
|
||||
│ ├─session-3.scope
|
||||
│ │ ├─1218 sshd: dboth [priv]
|
||||
│ │ ├─1233 sshd: dboth@pts/1
|
||||
│ │ └─1235 -bash
|
||||
│ └─session-7.scope
|
||||
│ ├─370621 /usr/libexec/lxdm-session
|
||||
│ ├─370631 xfce4-session
|
||||
│ ├─370805 /usr/bin/VBoxClient --clipboard
|
||||
│ ├─370806 /usr/bin/VBoxClient --clipboard
|
||||
│ ├─370817 /usr/bin/VBoxClient --seamless
|
||||
│ ├─370818 /usr/bin/VBoxClient --seamless
|
||||
│ ├─370824 /usr/bin/VBoxClient --draganddrop
|
||||
│ ├─370825 /usr/bin/VBoxClient --draganddrop
|
||||
│ ├─370841 /usr/bin/ssh-agent /bin/sh -c exec -l bash -c "/usr/bin/startxfce4"
|
||||
│ ├─370910 /bin/gpg-agent --sh --daemon --write-env-file /home/dboth/.cache/gpg-agent-info
|
||||
│ ├─370911 xfwm4 --display :0.0 --sm-client-id 2dead44ab-0b4d-4101-bca4-e6771f4a8ac2
|
||||
│ ├─370923 xfsettingsd --display :0.0 --sm-client-id 261b4a437-3029-461c-9551-68c2c42f4fef
|
||||
│ ├─370930 xfce4-panel --display :0.0 --sm-client-id 2ce38b8ef-86fd-4189-ace5-deec1d0e0952
|
||||
│ ├─370934 Thunar --sm-client-id 2cfc809d8-4e1d-497a-a5c5-6e4fa509c3fb --daemon
|
||||
│ ├─370939 xfdesktop --display :0.0 --sm-client-id 299be0608-4dca-4055-b4d6-55ec6e73a324
|
||||
<SNIP>
|
||||
└─system.slice
|
||||
├─rngd.service
|
||||
│ └─1650 /sbin/rngd -f
|
||||
├─irqbalance.service
|
||||
│ └─1631 /usr/sbin/irqbalance --foreground
|
||||
├─fprintd.service
|
||||
│ └─303383 /usr/libexec/fprintd
|
||||
├─systemd-udevd.service
|
||||
│ └─956 /usr/lib/systemd/systemd-udevd
|
||||
<SNIP>
|
||||
├─systemd-journald.service
|
||||
│ └─588 /usr/lib/systemd/systemd-journald
|
||||
├─atd.service
|
||||
│ └─1010 /usr/sbin/atd -f
|
||||
├─system-dbus\x2d:1.10\x2dorg.freedesktop.problems.slice
|
||||
│ └─dbus-:[1.10-org.freedesktop.problems@0.service][10]
|
||||
│ └─371197 /usr/sbin/abrt-dbus -t133
|
||||
├─sshd.service
|
||||
│ └─893 sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups
|
||||
├─vboxservice.service
|
||||
│ └─802 /usr/sbin/VBoxService -f
|
||||
├─crond.service
|
||||
│ └─1011 /usr/sbin/crond -n
|
||||
├─NetworkManager.service
|
||||
│ └─765 /usr/sbin/NetworkManager --no-daemon
|
||||
├─switcheroo-control.service
|
||||
│ └─787 /usr/libexec/switcheroo-control
|
||||
<SNIP>
|
||||
```
|
||||
|
||||
This tree view shows all of the user and system slices and the services and programs running in each cgroup. Notice the units called "scopes," which group related programs into a management unit, within the `user-1000.slice` in the listing above. The `user-1000.slice/session-7.scope` cgroup contains the GUI desktop program hierarchy, starting with the LXDM display manager session and all of its subtasks, including things like the Bash shell and the Thunar GUI file manager.
|
||||
|
||||
Scope units are not defined in configuration files but are generated programmatically as the result of starting groups of related programs. Scope units do not create or start the processes running as part of that cgroup. All processes within the scope are equal, and there is no internal hierarchy. The life of a scope begins when the first process is created and ends when the last process is destroyed.
|
||||
|
||||
Open several windows on your desktop, such as terminal emulators, LibreOffice, or whatever you want, then switch to an available virtual console and start something like `top` or [Midnight Commander][11]. Run the `systemd-cgls` command on your host, and take note of the overall hierarchy and the scope units.
|
||||
|
||||
The `systemd-cgls` command provides a more complete representation of the cgroup hierarchy (and details of the units that make it up) than any other command I have found. I prefer its cleaner representation of the tree than what the `ps` command provides.
|
||||
|
||||
### With a little help from my friends
|
||||
|
||||
After covering these basics, I had planned to go into more detail about cgroups and how to use them, but I discovered a series of four excellent articles by Red Hat's [Steve Ovens][12] on Opensource.com's sister site [Enable Sysadmin][13]. Rather then basically rewriting Steve's articles, I decided it would be much better to take advantage of his cgroup expertise by linking to them:
|
||||
|
||||
1. [A Linux sysadmin's introduction to cgroups][14]
|
||||
2. [How to manage cgroups with CPUShares][15]
|
||||
3. [Managing cgroups the hard way—manually][16]
|
||||
4. [Managing cgroups with systemd][17]
|
||||
|
||||
|
||||
|
||||
Enjoy and learn from them, as I did.
|
||||
|
||||
### Other resources
|
||||
|
||||
There is a great deal of information about systemd available on the internet, but much is terse, obtuse, or even misleading. In addition to the resources mentioned in this article, the following webpages offer more detailed and reliable information about systemd startup. This list has grown since I started this series of articles to reflect the research I have done.
|
||||
|
||||
* The Fedora Project has a good, practical [guide][18] [to systemd][18]. It has pretty much everything you need to know in order to configure, manage, and maintain a Fedora computer using systemd.
|
||||
* The Fedora Project also has a good [cheat sheet][19] that cross-references the old SystemV commands to comparable systemd ones.
|
||||
* The [systemd.unit(5) manual page][20] contains a nice list of unit file sections and their configuration options along with concise descriptions of each.
|
||||
* Red Hat documentation contains a good description of the [Unit file structure][21] as well as other important information.
|
||||
* For detailed technical information about systemd and the reasons for creating it, check out Freedesktop.org's [description of systemd][22]. This page is one of the best I have found because it contains many links to other important and accurate documentation.
|
||||
* Linux.com's "More systemd fun" offers more advanced systemd [information and tips][23].
|
||||
* See the man page for [systemd.resource-control(5)][24].
|
||||
* In [_The Linux kernel user's and administrator's guide_][25], see the [Control Group v2][26] entry.
|
||||
|
||||
|
||||
|
||||
There is also a series of deeply technical articles for Linux sysadmins by Lennart Poettering, the designer and primary developer of systemd. These articles were written between April 2010 and September 2011, but they are just as relevant now as they were then. Much of everything else good that has been written about systemd and its ecosystem is based on these papers.
|
||||
|
||||
* [Rethinking PID 1][27]
|
||||
* [systemd for Administrators, Part I][28]
|
||||
* [systemd for Administrators, Part II][29]
|
||||
* [systemd for Administrators, Part III][30]
|
||||
* [systemd for Administrators, Part IV][31]
|
||||
* [systemd for Administrators, Part V][32]
|
||||
* [systemd for Administrators, Part VI][33]
|
||||
* [systemd for Administrators, Part VII][34]
|
||||
* [systemd for Administrators, Part VIII][35]
|
||||
* [systemd for Administrators, Part IX][36]
|
||||
* [systemd for Administrators, Part X][37]
|
||||
* [systemd for Administrators, Part XI][38]
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/20/10/cgroups
|
||||
|
||||
作者:[David Both][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/dboth
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lenovo-thinkpad-laptop-concentration-focus-windows-office.png?itok=-8E2ihcF (Woman using laptop concentrating)
|
||||
[2]: https://en.wikipedia.org/wiki/Top_(software)
|
||||
[3]: https://opensource.com/article/19/11/monitoring-linux-glances
|
||||
[4]: https://opensource.com/article/20/4/systemd
|
||||
[5]: https://en.wikipedia.org/wiki/Cgroups
|
||||
[6]: mailto:user@0.service
|
||||
[7]: mailto:user@1000.service
|
||||
[8]: mailto:1.2-org.xfce.Xfconf@0.service
|
||||
[9]: mailto:1.2-ca.desrt.dconf@0.service
|
||||
[10]: mailto:1.10-org.freedesktop.problems@0.service
|
||||
[11]: https://midnight-commander.org/
|
||||
[12]: https://www.redhat.com/sysadmin/users/steve-ovens
|
||||
[13]: https://www.redhat.com/sysadmin/
|
||||
[14]: https://www.redhat.com/sysadmin/cgroups-part-one
|
||||
[15]: https://www.redhat.com/sysadmin/cgroups-part-two
|
||||
[16]: https://www.redhat.com/sysadmin/cgroups-part-three
|
||||
[17]: https://www.redhat.com/sysadmin/cgroups-part-four
|
||||
[18]: https://docs.fedoraproject.org/en-US/quick-docs/understanding-and-administering-systemd/index.html
|
||||
[19]: https://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet
|
||||
[20]: https://man7.org/linux/man-pages/man5/systemd.unit.5.html
|
||||
[21]: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/managing-services-with-systemd_configuring-basic-system-settings#Managing_Services_with_systemd-Unit_File_Structure
|
||||
[22]: https://www.freedesktop.org/wiki/Software/systemd/
|
||||
[23]: https://www.linux.com/training-tutorials/more-systemd-fun-blame-game-and-stopping-services-prejudice/
|
||||
[24]: https://man7.org/linux/man-pages/man5/systemd.resource-control.5.html
|
||||
[25]: https://www.kernel.org/doc/html/latest/admin-guide/index.html
|
||||
[26]: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html
|
||||
[27]: http://0pointer.de/blog/projects/systemd.html
|
||||
[28]: http://0pointer.de/blog/projects/systemd-for-admins-1.html
|
||||
[29]: http://0pointer.de/blog/projects/systemd-for-admins-2.html
|
||||
[30]: http://0pointer.de/blog/projects/systemd-for-admins-3.html
|
||||
[31]: http://0pointer.de/blog/projects/systemd-for-admins-4.html
|
||||
[32]: http://0pointer.de/blog/projects/three-levels-of-off.html
|
||||
[33]: http://0pointer.de/blog/projects/changing-roots
|
||||
[34]: http://0pointer.de/blog/projects/blame-game.html
|
||||
[35]: http://0pointer.de/blog/projects/the-new-configuration-files.html
|
||||
[36]: http://0pointer.de/blog/projects/on-etc-sysinit.html
|
||||
[37]: http://0pointer.de/blog/projects/instances.html
|
||||
[38]: http://0pointer.de/blog/projects/inetd.html
|
@ -0,0 +1,167 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions)
|
||||
[#]: via: (https://itsfoss.com/apt-cache-command/)
|
||||
[#]: author: (Abhishek Prakash https://itsfoss.com/author/abhishek/)
|
||||
|
||||
How to Use apt-cache Command in Debian, Ubuntu and Other Linux Distributions
|
||||
======
|
||||
|
||||
_**With apt-cache command, you can search for package details in the local APT cache. Learn to use apt-cache command in this tutorial.**_
|
||||
|
||||
### What is apt-cache command used for?
|
||||
|
||||
The [apt][1] [package manager][2] works on a local cache of package metadata. The metadata usually consists information like package name, version, description, dependencies, its repository and developers. With the apt-cache command, you can query this local APT cache and get relevant information.
|
||||
|
||||
You can search for the availability of a package, its version number, its dependencies among other things. I’ll show you how to use the apt-cache command with examples.
|
||||
|
||||
The **location of APT cache** is /var/lib/apt/lists/ directory. Which repository metadata to cache depends on the repositories added in your source list in the /etc/apt/sources.list file and additional repository files located in ls /etc/apt/sources.list.d directory.
|
||||
|
||||
Surprisingly, apt-cache doesn’t clear the APT cache. For that you’ll have to [use the apt-get clean command][3].
|
||||
|
||||
Needless to say, the APT packaging system is used on Debian and Debian-based Linux distributions like Ubuntu, Linux Mint, elementary OS etc. You cannot use it on Arch or Fedora.
|
||||
|
||||
### Using apt-cache command
|
||||
|
||||
![][4]
|
||||
|
||||
Like any other Linux command, there are several options available with apt-cache and you can always refer to its man page to read about them.
|
||||
|
||||
However, you probably won’t need to use all of them. This is why I am going to show you only the most common and useful examples of the apt-cache command in this tutorial.
|
||||
|
||||
Always update
|
||||
|
||||
It is always a good idea to update the local APT cache to sync it with the remote repositories. How do you do that? You use the command:
|
||||
|
||||
**sudo apt update**
|
||||
|
||||
#### Search for packages
|
||||
|
||||
The most common use of apt-cache command is for finding package. You can use a regex pattern to search for a package in the local APT cache.
|
||||
|
||||
```
|
||||
apt-cache search package_name
|
||||
```
|
||||
|
||||
By default, it looks for the search term in both the name and description of the package. It shows the matching package along with its short description in alphabetical order.
|
||||
|
||||
![][5]
|
||||
|
||||
You can narrow down your search to look for the search term in package names only.
|
||||
|
||||
```
|
||||
apt-cache search --names-only package_name
|
||||
```
|
||||
|
||||
![][6]
|
||||
|
||||
If you want complete details of all the matched packages, you may use the `--full` flag. It can also be used with `--names-only` flag.
|
||||
|
||||
![][7]
|
||||
|
||||
#### Get detailed package information
|
||||
|
||||
If you know the exact package name (or if you have manged to find it with the search), you can get the detailed metadata information on the package.
|
||||
|
||||
```
|
||||
apt-cache show package_name
|
||||
```
|
||||
|
||||
![][8]
|
||||
|
||||
You can see all kind of details in the package metadata like name, version, developer, maintainer, repository, short and long description, package size and even checksum.
|
||||
|
||||
There is another option showpkg that displays information about the package name, version and its forward and reverse dependencies.
|
||||
|
||||
```
|
||||
apt-cache showpkg package_name
|
||||
```
|
||||
|
||||
#### apt-cache policy
|
||||
|
||||
This is one of the rarely used option of apt-cache command. The policy options helps you debug the issue related to the [preference file][9].
|
||||
|
||||
If you specify the package name, it will show whether the package is installed, which version is available from which repository and its priority.
|
||||
|
||||
![][10]
|
||||
|
||||
By default, each installed package version has a priority of 100 and a non-installed package has a priority of 500. The same package may have more than one version with a different priority. APT installs the version with higher priority unless the installed version is newer.
|
||||
|
||||
If this doesn’t make sense, it’s okay. It will be extremely rare for a regular Linux user to dwell this deep into package management.
|
||||
|
||||
#### Check dependencies and reverse dependencies of a package
|
||||
|
||||
You can [check the dependencies of a package][11] before (or even after) installing it. It also shows all the possible packages that can fulfill the dependency.
|
||||
|
||||
```
|
||||
apt-cache depends package
|
||||
```
|
||||
|
||||
![][12]
|
||||
|
||||
You may also check which packages are dependent on a certain package by checking the reverse dependencies with apt-cahce.
|
||||
|
||||
![][13]
|
||||
|
||||
Frankly, I was also surprised to see that a DevOps tool like Ansible has a dependency on a [funny Linux command like Cowsay][14]. I think it’s perhaps because after [installing Ansible][15], it displays some message on the nodes.
|
||||
|
||||
#### Check unmet dependencies
|
||||
|
||||
You may get troubled with [unmet dependencies issue in Ubuntu][16] or other Linux. The apt-cache command provides option to check all the unmet dependencies of various available packages on your system.
|
||||
|
||||
```
|
||||
apt-cache unmet
|
||||
```
|
||||
|
||||
![][17]
|
||||
|
||||
**Conclusion**
|
||||
|
||||
You can list all available packages with the apt-cache command. The output would be huge, so I suggest combining it with [wc command][18] to get a total number of available packages like this:
|
||||
|
||||
```
|
||||
apt-cache pkgnames | wc -l
|
||||
```
|
||||
|
||||
Did you notice that you don’t need to be [root user][19] for using apt-cache command?
|
||||
|
||||
The newer [apt command][20] has a few options available to match the features of apt-cache command. Since apt is new, apt-get and its associated commands like apt-cache are still preferred to be used in scripts.
|
||||
|
||||
I hope you find this tutorial helpful. If you have questions about any point discussed above or suggestion to improve it, please let me know in the comments.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/apt-cache-command/
|
||||
|
||||
作者:[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://wiki.debian.org/Apt
|
||||
[2]: https://itsfoss.com/package-manager/
|
||||
[3]: https://itsfoss.com/clear-apt-cache/
|
||||
[4]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-command.png?resize=800%2C450&ssl=1
|
||||
[5]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-search.png?resize=759%2C437&ssl=1
|
||||
[6]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-search-names-only.png?resize=759%2C209&ssl=1
|
||||
[7]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-show-full.png?resize=759%2C722&ssl=1
|
||||
[8]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-show-pkgname.png?resize=800%2C795&ssl=1
|
||||
[9]: https://debian-handbook.info/browse/stable/sect.apt-get.html#sect.apt.priorities
|
||||
[10]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-policy.png?resize=795%2C456&ssl=1
|
||||
[11]: https://itsfoss.com/check-dependencies-package-ubuntu/
|
||||
[12]: https://i2.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-dependency-check.png?resize=768%2C304&ssl=1
|
||||
[13]: https://i1.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-reverse-dependency.png?resize=768%2C304&ssl=1
|
||||
[14]: https://itsfoss.com/funny-linux-commands/
|
||||
[15]: https://linuxhandbook.com/install-ansible-linux/
|
||||
[16]: https://itsfoss.com/held-broken-packages-error/
|
||||
[17]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2020/10/apt-cache-unmet.png?resize=759%2C399&ssl=1
|
||||
[18]: https://linuxhandbook.com/wc-command/
|
||||
[19]: https://itsfoss.com/root-user-ubuntu/
|
||||
[20]: https://itsfoss.com/apt-command-guide/
|
@ -1,56 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( chenmu-kk )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (My first contribution to open source: Making a decision)
|
||||
[#]: via: (https://opensource.com/article/19/11/my-first-open-source-contribution-mistake-decisions)
|
||||
[#]: author: (Galen Corey https://opensource.com/users/galenemco)
|
||||
|
||||
我的第一次开源贡献:做出决定
|
||||
======
|
||||
一位新的开源贡献者记录了她加入到开源项目后开始犯得五个错误。
|
||||
|
||||
![Lightbulb][1]
|
||||
|
||||
先前,我将大量的责任归咎于[冒充综合症][2]因为这延迟了我的第一个开源贡献。但还有一个我无法忽视的因素:我无法做决定来拯救我的生活。 在[成千上百万][3]的开源项目中抉择时,选择一个要做贡献的项目势不可挡。如此压迫以至于我常常不得不关掉我的笔记本去思考:“或许我可以改天再做一次”。
|
||||
|
||||
错误二是让我对做决定的恐惧妨碍了我做出第一次贡献。在理想世界里,也许我会带着一个我真正关心和想去做的特定项目开始我的开源之旅,但我有的只是总得为开源项目做出的贡献的模糊目标。对于那些处于同一处境的人来说,这儿有一些策略可以为自己的贡献挑选合适的项目(或者至少是一个好的项目)。
|
||||
|
||||
### 我经常使用的工具
|
||||
|
||||
一开始,我不认为有必要将自己局限于已经熟悉的工具或项目。有一些我之前从未使用过,但由于他们活跃的社区,或者他们解决了有趣的问题,因此看起来很有吸引力。
|
||||
|
||||
但是,考虑我投入到这个项目中的时间有限,我决定继续使用我了解的工具。要了解工具需求,你需要熟悉它的工作方式。如果您想为自己不熟悉的项目做贡献,则需要完成一个额外的步骤来了解代码的功能和目标。这个额外的工作量是有趣且值得的,但也会使你的工作时间加倍。因为我的目标主要是贡献,坚持我所知道的是缩小范围一个很好的方式。回馈一个你认为有用的项目也是一种回报。
|
||||
|
||||
### 我经常使用的工具
|
||||
|
||||
一开始,我不认为有必要将自己局限于已经熟悉的工具或项目。有一些我之前从未使用过,但由于他们活跃的社区,或者他们解决了有趣的问题,因此看起来很有吸引力。
|
||||
|
||||
但是,考虑我投入到这个项目中的时间有限,我决定继续使用我了解的工具。要了解工具需求,你需要熟悉它的工作方式。如果您想为自己不熟悉的项目做贡献,则需要完成一个额外的步骤来了解代码的功能和目标。这个额外的工作量是有趣且值得的,但也会使你的工作时间加倍。因为我的目标主要是贡献,坚持我所知道的是缩小范围一个很好的方式。回馈一个你认为有用的项目也是一种回报。
|
||||
|
||||
因为这是我第一次为开源项目做出贡献,在此过程中我有很多问题。一些项目社区非常擅长记录选择问题和提出请求的程序。一些项目社区在记录流程方面很优秀,可以用来挑选其中的项目并提交请求。尽管那时我没有选择它们,因为在此之前我从未使用过该产品,[Gatsby][4]是该实践的一个范例。
|
||||
|
||||
这种细致的文件帮助我们缓解一些不知如何去做的不安全感。它也给了我希望,项目是开放给新的贡献者,并将花时间来查看我的工作。除了贡献准则外,我还查看了问题部分,看看这个项目是否利用了“好的第一个问题”标志。这是该项目对初学者开放的另一个标志(并帮助你学会如何操作)。
|
||||
|
||||
### 总结
|
||||
|
||||
如果你还没有计划好一个项目,那么选择合适的领域进行您的第一个开源贡献已势不可挡。列出一系列标准可以帮助自己缩减选择范围,并为自己的首次提交找到一个好的项目。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/my-first-open-source-contribution-mistake-decisions
|
||||
|
||||
作者:[Galen Corey][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[chenmu-kk](https://github.com/chenmu-kk)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/galenemco
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh (Lightbulb)
|
||||
[2]: https://opensource.com/article/19/10/my-first-open-source-contribution-mistakes
|
||||
[3]: https://github.blog/2018-02-08-open-source-project-trends-for-2018/
|
||||
[4]: https://www.gatsbyjs.org/contributing/
|
Loading…
Reference in New Issue
Block a user