Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 98 additions & 91 deletions docs/books/admin_guide/03-commands.zh.md

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions docs/books/admin_guide/05-vi.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ title: VI 文本编辑器

**目标**: 在本章中,未来的 Linux 管理员们将学习如何:

:heavy_check_mark: 使用VI编辑器的主要命令;
:heavy_check_mark: 使用VI编辑器的主要命令;
:heavy_check_mark: 使用VI编辑器修改文本。

:checkered_flag: **用户命令**,**linux**

**知识性**: :star:
**知识性**: :star:
**复杂度**: :star: :star:

**阅读时间**: 20 分钟
Expand All @@ -36,14 +36,14 @@ title: VI 文本编辑器

`vi` 命令可打开 *VI* 文本编辑器。

```
```bash
vi [-c command] [file]
```

示例:

```
$ vi /home/rockstar/file
```bash
vi /home/rockstar/file
```

| 选项 | 信息 |
Expand All @@ -58,7 +58,7 @@ $ vi /home/rockstar/file

`vim`编辑器对 VI 的界面和功能进行了许多改进。

```
```bash
vim [-c command] [file]
```

Expand All @@ -78,9 +78,9 @@ vim [-c command] [file]

要退出 VI ,请从 command 模式中按<kbd>:</kbd>,然后键入:

* `q`不保存退出(_quit_);
* `w` 保存当前你的工作内容(_write_);
* `wq`(_write quit_) 或者 `x`(_eXit_)保存并退出。
* `q`不保存退出(*quit*);
* `w` 保存当前你的工作内容(*write*);
* `wq`(*write quit*) 或者 `x`(*eXit*)保存并退出。

在命令模式下,连续两次单击大写状态的<kbd>Z</kbd>键即可保存并退出。

Expand Down Expand Up @@ -210,11 +210,11 @@ VI 的原理是在 *command* 模式和 *insertion* 模式之间交替使用。

* 在字符前插入文本:

<kbd>i</kbd> (_insert_)
<kbd>i</kbd> (*insert*)

* 在字符后插入文本:

<kbd>a</kbd> (_append_)
<kbd>a</kbd> (*append*)

### 与行相关的

Expand Down Expand Up @@ -292,7 +292,7 @@ VI 允许通过管理以下各项进行文本编辑:

* 替换一个单词:

<kbd>c</kbd><kbd>w</kbd><kbd>_word_</kbd><kbd>ESC</kbd>
<kbd>c</kbd><kbd>w</kbd><kbd>*word*</kbd><kbd>ESC</kbd>

!!! Tip "提示"

Expand Down Expand Up @@ -395,9 +395,9 @@ VI 允许通过管理以下各项进行文本编辑:

示例:

`/[Ww]ord`:搜索_word_ 或者 _Word_
`/[Ww]ord`:搜索*word* 或者 *Word*

`/[1-9]word`:搜索 _1word_、 _2word_... _`x`字_ 中, `x` 表示一个数字
`/[1-9]word`:搜索 *1word*、 *2word*... *`x`word* 中, `x` 表示一个数字

* `^` :搜索以某字符开头的行

Expand All @@ -415,7 +415,7 @@ VI 允许通过管理以下各项进行文本编辑:

示例:

`/W.rd` : 搜索 _Word__Ward_ ...
`/W.rd` : 搜索 *Word**Ward* ...

* `*` :前一个字符匹配的次数、0次或任意次数。

Expand Down Expand Up @@ -507,8 +507,8 @@ VI 允许通过管理以下各项进行文本编辑:

可通过指定为会话加载的选项来执行 VI 。 为此,您必须使用 `-c` 选项:

```
$ vi -c "set nu" /home/rockstar/file
```bash
vi -c "set nu" /home/rockstar/file
```

也可以在用户家目录下,在名为 `.exrc` 的文件中输入 <*>Ex* 命令。 在每次VI或VIM启动时,都将读取并应用命令。
Expand All @@ -517,6 +517,6 @@ $ vi -c "set nu" /home/rockstar/file

有一个学习如何使用 VI 的教程。 可以使用命令 `vimtutor` 访问它。

```
$ vimtutor
```bash
vimtutor
```
148 changes: 148 additions & 0 deletions docs/books/learning_rsync/02_rsync_demo01.fr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
title: démo rsync 01
author: tianci li
contributors: Steven Spencer, Ganna Zhyrnova
update: 2021-11-04
---

# Préface

`rsync` doit effectuer l'authentification de l'utilisateur avant la synchronisation des données. **Il y a deux méthodes de protocole d'authentification : protocole SSH et protocole rsync (le port par défaut de rsync est 873)**

* Méthode de connexion de vérification du protocole SSH : utiliser le protocole SSH comme base pour l'authentification de l'identité de l'utilisateur (c'est-à-dire utiliser l'utilisateur système et le mot de passe de GNU/Linux lui-même pour la vérification), puis effectuer une synchronisation des données.
* méthode de connexion de vérification du protocole rsync : utilisez le protocole rsync pour l'authentification de l'utilisateur (utilisateurs système non-GNU/Linux, similaires aux utilisateurs virtuels vsftpd), puis effectuez la synchronisation des données.

Avant la démonstration spécifique de la synchronisation rsync, vous devez utiliser la commande `rsync`. Dans Rocky Linux 8, le paquet rpm rsync est installé par défaut et la version est 3.1.3-12, comme suit :

```bash
[root@Rocky ~]# rpm -qa|grep rsync
rsync-3.1.3-12.el8.x86_64
```

```txt
Basic format: rsync [options] original location target location
Commonly used options:
-a: archive mode, recursive and preserves the attributes of the file object, which is equivalent to -rlptgoD (without -H, -A, -X)
-v: Display detailed information about the synchronization process
-z: compress when transferring files
-H: Keep hard link files
-A: retain ACL permissions
-X: retain chattr permissions
-r: Recursive mode, including all files in the directory and subdirectories
-l: still reserved for symbolic link files
-p: Permission to retain file attributes
-t: time to retain file attributes
-g: retain the group belonging to the file attribute (only for super users)
-o: retain the owner of the file attributes (only for super users)
-D: Keep device files and other special files
```

Utilisation favorisée par l'auteur : `rsync -avz original location target location`

## Description de l'environnement

| Élément | Observation |
| ----------------------- | ---------------- |
| Rocky Linux 8 (Serveur) | 192.168.100.4/24 |
| Fedora 34 (client) | 192.168.100.5/24 |

Vous pouvez utiliser Fedora 34 pour télécharger

```mermaid
graph LR;
RockyLinux8-->|pull/download|Fedora34;
Fedora34-->|push/upload|RockyLinux8;
```

Vous pouvez également utiliser Rocky Linux 8 pour télécharger

```mermaid
graph LR;
RockyLinux8-->|push/upload|Fedora34;
Fedora34-->|pull/download|RockyLinux8;
```

## Démonstration basée sur le protocole SSH

!!! tip "Astuce"

Ici, Rocky Linux 8 et Fedora 34 utilisent l'utilisateur root pour se connecter. Fedora 34 est le client et Rocky Linux 8 le serveur.

### pull/download

Puisqu'il est basé sur le protocole SSH, nous allons créer d'abord un utilisateur sur le serveur :

```bash
[root@Rocky ~]# useradd testrsync
[root@Rocky ~]# passwd testrsync
```

Du côté du client, nous utilisons pull/download et le fichier sur le serveur est /rsync/aabbcc

```bash
[root@fedora ~]# rsync -avz testrsync@192.168.100.4:/rsync/aabbcc /root
testrsync@192.168.100.4 ' s password:
receiving incremental file list
aabbcc
sent 43 bytes received 85 bytes 51.20 bytes/sec
total size is 0 speedup is 0.00
[root@fedora ~]# cd
[root@fedora ~]# ls
aabbcc
```
Le transfert a réussi.

!!! tip "Astuce"

Si le port SSH du serveur n'est pas le port par défaut 22, vous pouvez spécifier le port de manière similaire---`rsync -avz -e 'ssh -p [port]' `.

### push/upload

```bash
[root@fedora ~]# touch fedora
[root@fedora ~]# rsync -avz /root/* testrsync@192.168.100.4:/rsync/
testrsync@192.168.100.4 ' s password:
sending incremental file list
anaconda-ks.cfg
fedora
rsync: mkstemp " /rsync/.anaconda-ks.cfg.KWf7JF " failed: Permission denied (13)
rsync: mkstemp " /rsync/.fedora.fL3zPC " failed: Permission denied (13)
sent 760 bytes received 211 bytes 277.43 bytes/sec
total size is 883 speedup is 0.91
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender = 3.2.3]
```

**Demande de permission refusée, comment y faire face ?**

Vérifiez d'abord les permissions du répertoire /rsync/ . Évidemment, il n'y a pas de permission "w". Nous pouvons utiliser `setfacl` pour accorder des permission :

```bash
[root@Rocky ~ ] # ls -ld /rsync/
drwxr-xr-x 2 root root 4096 November 2 15:05 /rsync/
```

```bash
[root@Rocky ~ ] # setfacl -mu:testrsync:rwx /rsync/
[root@Rocky ~ ] # getfacl /rsync/
getfacl: Removing leading ' / ' from absolute path names
# file: rsync/
# owner: root
# group: root
user::rwx
user:testrsync:rwx
group::rx
mask::rwx
other::rx
```

Essayez à nouveau !

```bash
[root@fedora ~ ] # rsync -avz /root/* testrsync@192.168.100.4:/rsync/
testrsync@192.168.100.4 ' s password:
sending incremental file list
anaconda-ks.cfg
fedora
sent 760 bytes received 54 bytes 180.89 bytes/sec
total size is 883 speedup is 1.08
```
129 changes: 129 additions & 0 deletions docs/books/learning_rsync/03_rsync_demo02.fr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
title: rsync demo 02
author: tianci li
contributors: Steven Spencer, Ganna Zhyrnova
update: 2021-11-04
---

# Démonstration basée sur le protocole rsync
Dans vsftpd, il y a des utilisateurs virtuels (utilisateurs personnalisés par l'administrateur) parce qu'il est très déconseillé d'utiliser des utilisateurs anonymes et des utilisateurs locaux. Nous savons qu'un serveur basé sur le protocole SSH doit s'assurer qu'il y a un système d'utilisateurs. Quand il y a beaucoup d'exigences de synchronisation, il peut être nécessaire de créer de nombreux utilisateurs. Cela ne répond évidemment pas aux normes de fonctionnement et de maintenance de GNU/Linux (plus il y a d'utilisateurs, plus il y a d'utilisateurs non sécurisés). Dans rsync, pour des raisons de sécurité, il y a une méthode d'authentification du protocole rsync.

**Comment faire?**

Il suffit d'écrire les paramètres et valeurs correspondants dans le fichier de configuration. Dans Rocky Linux 8, vous devez créer manuellement le fichier <font color=red>/etc/rsyncd.conf</font>.

```bash
[root@Rocky ~]# touch /etc/rsyncd.conf
[root@Rocky ~]# vim /etc/rsyncd.conf
```

Some parameters and values of this file are as follows, [ here ](04_rsync_configure.md) has more parameter descriptions:

| Élément | Observation |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| address = 192.168.100.4 | L'adresse IP sur laquelle rsync écoute par défaut |
| port = 873 | port d'écoute par défaut de rsync |
| pid file = /var/run/rsyncd.pid | Emplacement du fichier pid du processus |
| log file = /var/log/rsyncd.log | Emplacement du fichier log |
| [share] | Partage de nom |
| comment = rsync | Remarques ou informations de description |
| path = /rsync/ | L'emplacement du chemin système où il est situé |
| read only = yes | yes signifie lecture seule, pas d'écriture |
| dont compress = \*.gz \*.gz2 \*.zip | Quels types de fichiers ne sont pas compressés |
| auth users = li | Activez les utilisateurs virtuels et définissez un utilisateur virtuel. Besoin de le créer vous-même |
| secrets file = /etc/rsyncd_users.db | Utilisé pour spécifier l'emplacement du fichier de mot de passe de l'utilisateur virtuel, qui doit se terminer en .db. Le format de contenu du fichier est "Username : mot de passe", un par ligne |

!!! tip "Astuce"

La permission du fichier de mot de passe doit être <font color=red>600</font>.

Écrire du contenu du fichier dans <font color=red>/etc/rsyncd.conf</font> et écrire le nom d'utilisateur et le mot de passe dans /etc/rsyncd_users.db, la permission est de 600

```bash
[root@Rocky ~]# cat /etc/rsyncd.conf
address = 192.168.100.4
port = 873
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
[share]
comment = rsync
path = /rsync/
read only = yes
dont compress = *.gz *.bz2 *.zip
auth users = li
secrets file = /etc/rsyncd_users.db
[root@Rocky ~]# ll /etc/rsyncd_users.db
-rw------- 1 root root 9 November 2 16:16 /etc/rsyncd_users.db
[root@Rocky ~]# cat /etc/rsyncd_users.db
li:13579
```

Vous devrez peut-être executer `dnf -y install rsync-daemon` avant de pouvoir démarrer le service : `systemctl start rsyncd.service`

```bash
[root@Rocky ~]# systemctl start rsyncd.service
[root@Rocky ~]# netstat -tulnp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 691/sshd
tcp 0 0 192.168.100.4:873 0.0.0.0:* LISTEN 4607/rsync
tcp6 0 0 :::22 :::* LISTEN 691/sshd
udp 0 0 127.0.0.1:323 0.0.0.0:* 671/chronyd
udp6 0 0 ::1:323 :::* 671/chronyd
```

## pull/download

Créer un fichier dans le serveur pour vérification : `[root@Rocky]# touch /rsync/rsynctest.txt`

Le client fait ce qui suit :

```bash
[root@fedora ~]# rsync -avz li@192.168.100.4::share /root
Password:
receiving incremental file list
./
rsynctest.txt
sent 52 bytes received 195 bytes 7.16 bytes/sec
total size is 883 speedup is 3.57
[root@fedora ~]# ls
aabbcc anaconda-ks.cfg fedora rsynctest.txt
```

success ! En plus de l'écriture ci-dessus basée sur le protocole rsync, vous pouvez également écrire comme ceci : `rsync://li@10.1.2.84/share`

## push/upload

```bash
[root@fedora ~]# touch /root/fedora.txt
[root@fedora ~]# rsync -avz /root/* li@192.168.100.4::share
Password:
sending incremental file list
rsync: [sender] read error: Connection reset by peer (104)
rsync error: error in socket IO (code 10) at io.c(784) [sender = 3.2.3]
```

On vous indique que l'erreur de lecture est liée à la configuration "read only = yes" du serveur. Changez-la en "no" et redémarrez le service `[root@Rocky ~]# systemctl restart rsyncd.service`

Essayez à nouveau, à l'affichage de la permission refusée :

```bash
[root@fedora ~]# rsync -avz /root/* li@192.168.100.4::share
Password:
sending incremental file list
fedora.txt
rsync: mkstemp " /.fedora.txt.hxzBIQ " (in share) failed: Permission denied (13)
sent 206 bytes received 118 bytes 92.57 bytes/sec
total size is 883 speedup is 2.73
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender = 3.2.3]
```

Notre utilisateur virtuel ici est <font color=red>li</font>, qui est mappé à l'utilisateur système <font color=red>nobody</font> par défaut. Bien sûr, vous pouvez le changer à d'autres utilisateurs du système. En d'autres termes, nobody n'a pas de permission d'écriture dans le répertoire /rsync/ . Bien sûr, nous pouvons utiliser `[root@Rocky ~]# setfacl -mu:nobody:rwx /rsync/` , essayer à nouveau.

```bash
[root@fedora ~]# rsync -avz /root/* li@192.168.100.4::share
Password:
sending incremental file list
fedora.txt
sent 206 bytes received 35 bytes 96.40 bytes/sec
total size is 883 speedup is 3.66
```
Loading