synchronization
Some checks failed
continuous-integration/drone Build is failing

This commit is contained in:
2025-08-25 15:57:40 +08:00
commit cee91802b3
106 changed files with 9124 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
> 本文作者:丁辉
# Linux部署NFS存储
[官方](https://nfs.sourceforge.net/)
| 节点 | IP |
| :--: | :----------: |
| NFS | 192.168.1.10 |
1. 部署 Nfs 程序
- Centos部署
```bash
yum install nfs-utils rpcbind -y
```
- Ubuntu部署
```bash
apt install nfs-kernel-server -y
```
>客户端部署 `apt install nfs-common -y` 正常情况下安装 `nfs-kernel-server` 会自动安装客户端
2. 创建共享目录
```bash
mkdir /data
chmod -R 777 /data
```
3. 添加配置文件
```bash
echo "/data 192.168.1.0/24(rw,sync,insecure,no_subtree_check,no_root_squash)" >> /etc/exports
```
> 允许所有(不建议在生产使用)
>
> ```bash
> echo "/data *(rw,sync,insecure,no_subtree_check,no_root_squash)" >> /etc/exports
> ```
4. 启动 Nfs
```
systemctl start rpcbind
systemctl start nfs-server
systemctl enable rpcbind
systemctl enable nfs-server
```
5. 查看
```bash
showmount -e 127.0.0.1
```
## 其它节点挂载 Nfs 存储到本地
> NFS 节点开放端口
>
> - NFS服务端口(Mountd)
>
> ```bash
> iptables -A INPUT -p tcp --dport 2049 -j ACCEPT
> iptables -A INPUT -p udp --dport 2049 -j ACCEPT
> ```
>
> - Portmapper(端口映射程序)
>
> ```bash
> iptables -A INPUT -p tcp --dport 111 -j ACCEPT
> iptables -A INPUT -p udp --dport 111 -j ACCEPT
> ```
- 手动挂载
```bash
mount.nfs 192.168.1.10:/data /data
```
- 开机自动挂载
```bash
echo "192.168.1.10:/data /data nfs defaults 0 0" >> /etc/fstab
```
## Nfs 参数解释
参考 man 文档配置参数
```bash
man exports
```
**参数解释**
| 参数 | 解释 |
| ---------------- | ------------------------------------------------------------ |
| rw | 允许客户端对共享的文件系统进行读写操作。 |
| sync | 所有对共享文件系统的写操作都会同步到存储设备上。 |
| insecure | 允许不安全的客户端访问共享的文件系统。 |
| no_subtree_check | 禁止对子目录进行共享级别的访问控制检查。 |
| no_root_squash | 不对远程 root 用户进行权限限制,允许其以 root 身份访问共享。 |
## Exportfs参数解释
修改 exportfs 后重新加载配置
```bash
exportfs -arv
```
**参数解释**
| 选项 | 解释 |
| ---- | ------------------------------------------------------ |
| -a | 导出或取消导出 /etc/exports 文件中列出的所有文件系统。 |
| -r | 刷新 /etc/exports 文件并重新加载 NFS 导出。 |
| -v | 输出详细的日志信息,包括正在进行的操作和任何错误消息。 |

View File

@@ -0,0 +1,28 @@
> 本文作者:丁辉
# NFS服务优化
> NFS内核优化
```bash
cat >>/etc/sysctl.conf<<EOF
sunrpc.tcp_slot_table_entries=128
sunrpc.udp_slot_table_entries=128
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
EOF
sysctl -p
```
**参数解释**
| 参数 | 描述 |
| :---------------------------: | :----------------------------------------------------------: |
| sunrpc.tcp_slot_table_entries | TCP 协议下 RPC 服务的 slot table entries 数量。 |
| sunrpc.udp_slot_table_entries | UDP 协议下 RPC 服务的 slot table entries 数量。 |
| net.core.wmem_default | 此参数表示TCP连接的默认套接字发送缓冲区大小以字节为单位。它确定为每个套接字分配的发送缓冲区的初始大小。 |
| net.core.rmem_default | 此参数表示TCP连接的默认套接字接收缓冲区大小以字节为单位。它确定为每个套接字分配的接收缓冲区的初始大小。 |
| net.core.wmem_max | 此参数表示TCP连接的最大套接字发送缓冲区大小以字节为单位。它限制了每个套接字的发送缓冲区可以增长到的最大大小。 |
| net.core.rmem_max | 此参数表示TCP连接的最大套接字接收缓冲区大小以字节为单位。它限制了每个套接字的接收缓冲区可以增长到的最大大小。 |

View File

@@ -0,0 +1,221 @@
> 本文作者:丁辉
# Nfs高可用实现Rsync+Inotify
| 节点名称 | IP | 角色 | 同步目录 |
| :----------: | :----------: | :--------: | :------: |
| nfs-master-1 | 192.168.1.10 | NFS主节点1 | /data |
| nfs-master-2 | 192.168.1.20 | NFS主节点2 | /data |
> 适用架构: amd64
>
> 适用架构: arm64
## 开始部署 rsync
[Rsync常用参数解释](https://gitee.com/offends/Linux/blob/main/%E5%AD%98%E5%82%A8/NFS/Rsync%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0%E8%A7%A3%E9%87%8A.md)
> 所有节点执行
1. 安装 rsync
- Centos
```bash
yum install rsync -y
```
- Ubuntu
```bash
apt install rsync -y
```
2. 配置 rsync 配置文件
> 备份配置文件
>
> ```bash
> mv /etc/rsyncd.conf /etc/rsyncd.conf.bak
> ```
获取配置文件
[配置文件地址](https://gitee.com/offends/Linux/blob/main/File/Conf/rsyncd.conf)
```text
curl -so /etc/rsyncd.conf https://gitee.com/offends/Linux/raw/main/File/Conf/rsyncd.conf
```
替换内容如下(根据自己环境配置进行修改)
- nfs-master-1
```bash
sed -i 's#comment = none#comment = backup to nfs-master-2#g' /etc/rsyncd.conf
sed -i 's#hosts allow = none#hosts allow = 192.168.1.20/24#g' /etc/rsyncd.conf
```
- nfs-master-2
```bash
sed -i 's#comment = none#comment = backup to nfs-master-1#g' /etc/rsyncd.conf
sed -i 's#hosts allow = none#hosts allow = 192.168.1.10/24#g' /etc/rsyncd.conf
```
3. 相互配置认证文件
> 格式为: '用户:用户密码' (根据自己需求修改)
- nfs-master-1 和 nfs-master-2
```bash
echo 'rsync:password' > /etc/rsync_salve.pass
chmod 600 /etc/rsync_salve.pass
echo "password" > /etc/rsync.paschmod 600 /etc/rsync_salve.passs
chmod 600 /etc/rsync.pass
```
4. 启动服务
- Centos
```bash
systemctl enable rsyncd.service
systemctl start rsyncd.service
```
- Ubuntu
```bash
systemctl enable rsync.service
systemctl start rsync.service
```
5. 同步测试
- 192.168.1.10 传输文件到 192.168.1.20
```bash
rsync -arv --delete /data/ rsync@192.168.1.20::data --password-file=/etc/rsync.pass
```
- 192.168.1.20 传输文件到 192.168.1.10
```bash
rsync -arv --delete /data/ rsync@192.168.1.10::data --password-file=/etc/rsync.pass
```
> 开放防火墙
>
> ```bash
> iptables -A INPUT -p tcp --dport 873 -j ACCEPT
> ```
## 开始部署 inotify
1. 安装 inotify
- Centos
```bash
yum install epel-release -y
yum install inotify-tools -y
```
- Ubuntu
```bash
apt install inotify-tools
```
>Ubuntu配置文件位置`/etc/default/rsync`
2. 获取配置文件
> 脚本经过优化, 可良好降低服务器消耗
[同步脚本地址](https://gitee.com/offends/Linux/blob/main/File/Shell/rsync_inotify.sh)
```bash
curl -so /opt/rsync_inotify.sh https://gitee.com/offends/Linux/raw/main/File/Shell/rsync_inotify.sh && chmod 777 /opt/rsync_inotify.sh
```
3. 配置 inotify 同步脚本(根据自己环境配置进行修改)
- nfs-master-1
```bash
sed -i 's#HOST=none#HOST=192.168.1.20#g' /opt/rsync_inotify.sh
```
- nfs-master-2
```bash
sed -i 's#HOST=none#HOST=192.168.1.10#g' /opt/rsync_inotify.sh
```
**参数解释**
- `modify`:文件内容被修改。
- `create`:文件或目录被创建。
- `delete`:文件或目录被删除。
- `attrib`:文件或目录的属性被修改。
- `close_write`:文件被关闭(通常在写入完成后触发)。
- `move`:文件或目录被移动。
4. 将 inotify 纳入 system 管理
> 我觉得网上的 `nohup sh /opt/rsync_inotify.sh &` 的启动方式肯定是没有 system 管理合适的
将 inotify 纳入 system 管理
[Service文件地址](https://gitee.com/offends/Linux/blob/main/File/Service/inotify.service)
```bash
curl -so /etc/systemd/system/inotify.service https://gitee.com/offends/Linux/raw/main/File/Service/inotify.service
```
5. 启动 inotify
```bash
systemctl daemon-reload
systemctl enable inotify
systemctl start inotify
```
6. 配置全量备份定时任务
```bash
crontab -e
```
- nfs-master-1
```bash
* */2 * * * rsync -avzP --password-file=/etc/rsync.pass /data/ rsync@192.168.1.20::data
```
- nfs-master-2
```bash
* */2 * * * rsync -avzP --password-file=/etc/rsync.pass /data/ rsync@192.168.1.10::data
```
## 优化 inotify
> 修改 `/proc/sys/fs/inotify` 目录下的文件,调大数值即可
**参数解释**
| 参数 | 解释 |
| :----------------: | :----------------------------------------------------------: |
| max_user_watches | 这个参数定义了每个Inotify实例能够监控的文件或目录数量上限。如果你需要监控大量的文件或目录你可能需要增加这个值。 |
| max_user_instances | 这个参数定义了每个用户能够创建的Inotify实例的数量上限。如果你的应用程序需要同时监控多个目录你可能需要增加这个值。同样要注意不要将其设置得过高以免占用过多系统资源。 |
| max_queued_events | 这个参数定义了Inotify队列中可以排队的事件数量上限。如果你的应用程序需要监控大量的文件你可能需要增加这个值以确保不会丢失任何事件。但是要注意不要将其设置得过高以免消耗过多的内存资源。 |

View File

@@ -0,0 +1,209 @@
> 本文作者:丁辉
# Nfs高可用实现Rsync+Sersync2
| 节点名称 | IP | 角色 | 同步目录 |
| :----------: | :----------: | :--------: | :------: |
| nfs-master-1 | 192.168.1.10 | NFS主节点1 | /data |
| nfs-master-2 | 192.168.1.20 | NFS主节点2 | /data |
> 适用架构: x86
## 开始部署 rsync
[Rsync常用参数解释](https://gitee.com/offends/Linux/blob/main/%E5%AD%98%E5%82%A8/NFS/Rsync%E5%B8%B8%E7%94%A8%E5%8F%82%E6%95%B0%E8%A7%A3%E9%87%8A.md)
> 所有节点执行
1. 安装 rsync
- Centos
```bash
yum install rsync -y
```
- Ubuntu
```bash
apt install rsync -y
```
2. 配置 rsync 配置文件
> 备份配置文件
>
> ```bash
> mv /etc/rsyncd.conf /etc/rsyncd.conf.bak
> ```
获取配置文件
[配置文件地址](https://gitee.com/offends/Linux/blob/main/File/Conf/rsyncd.conf)
```text
curl -so /etc/rsyncd.conf https://gitee.com/offends/Linux/raw/main/File/Conf/rsyncd.conf
```
替换内容如下(根据自己环境配置进行修改)
- nfs-master-1
```bash
sed -i 's#comment = none#comment = backup to nfs-master-2#g' /etc/rsyncd.conf
sed -i 's#hosts allow = none#hosts allow = 192.168.1.20/24#g' /etc/rsyncd.conf
```
- nfs-master-2
```bash
sed -i 's#comment = none#comment = backup to nfs-master-1#g' /etc/rsyncd.conf
sed -i 's#hosts allow = none#hosts allow = 192.168.1.10/24#g' /etc/rsyncd.conf
```
3. 相互配置认证文件
> 格式为: '用户:用户密码' (根据自己需求修改)
- nfs-master-1 和 nfs-master-2
```bash
echo 'rsync:password' > /etc/rsync_salve.pass
chmod 600 /etc/rsync_salve.pass
echo "password" > /etc/rsync.paschmod 600 /etc/rsync_salve.passs
chmod 600 /etc/rsync.pass
```
4. 启动服务
- Centos
```bash
systemctl enable rsyncd.service
systemctl start rsyncd.service
```
- Ubuntu
```bash
systemctl enable rsync.service
systemctl start rsync.service
```
5. 同步测试
- 192.168.1.10 传输文件到 192.168.1.20
```bash
rsync -arv --delete /data/ rsync@192.168.1.20::data --password-file=/etc/rsync.pass
```
- 192.168.1.20 传输文件到 192.168.1.10
```bash
rsync -arv --delete /data/ rsync@192.168.1.10::data --password-file=/etc/rsync.pass
```
> 开放防火墙
>
> ```bash
> iptables -A INPUT -p tcp --dport 873 -j ACCEPT
> ```
## 开始部署 Sersync2
[下载地址](https://code.google.com/archive/p/sersync/downloads)
1. 下载文件
```bash
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/sersync/sersync2.5.4_64bit_binary_stable_final.tar.gz
```
2. 解压文件包
```bash
tar -zxvf sersync*_64bit_binary_stable_final.tar.gz && mv GNU-Linux-x86/ /usr/local/sersync
```
3. 修改配置文件
```bash
mv /usr/local/sersync/confxml.xml /usr/local/sersync/confxml.xml.bak
```
下载配置文件
[配置文件内容解释](https://gitee.com/offends/Linux/blob/main/File/Xml/confxml.xml)
```bash
curl -so /usr/local/sersync/confxml.xml https://gitee.com/offends/Linux/raw/main/File/Xml/confxml.xml
```
修改如下内容(清根据自己需求修改配置文件其它参数)
- nfs-master-1
```bash
sed -ri '25s#<remote ip="127.0.0.1" name="tongbu1"/>#<remote ip="192.168.1.20" name="data"/>#g' confxml.xml
```
- nfs-master-2
```bash
sed -ri '25s#<remote ip="127.0.0.1" name="tongbu1"/>#<remote ip="192.168.1.10" name="data"/>#g' confxml.xml
```
4. 配置 Sersync2 纳入 System 管理
[System文件地址](https://gitee.com/offends/Linux/blob/main/File/Service/sersync2.service)
```bash
curl -so /etc/systemd/system/sersync2.service https://gitee.com/offends/Linux/raw/main/File/Service/sersync2.service
```
5. 启动 sersync2
```bash
systemctl daemon-reload
systemctl enable sersync2
systemctl start sersync2
```
## Params 参数常用配置之间的优缺点
**artuz 选项**
1. 优点:
- 完全归档:该选项包括 `-a`archive选项它将复制文件的所有属性包括权限、所有者、时间戳等并执行递归复制以保持源目录结构的完整性。
- 保留时间戳:使用 `-t` 选项,它会保留文件的时间戳信息。
- 仅复制更新的文件:使用 `-u` 选项,只有当源文件更新时才会复制文件,这可以节省带宽和时间。
2. 不足:
- 复制速度较慢:由于会复制文件的属性和时间戳,可能会导致复制速度较慢,尤其是在大规模文件复制时。
**az 选项**
1. 优点:
- 启用压缩传输:该选项包括 `-z`compression选项它会在传输过程中启用压缩减少数据传输的大小特别适用于带宽有限的网络环境。
- 较快的传输速度:由于不复制文件属性和时间戳,传输速度通常较快。
2. 不足:
- 不会保留文件属性:使用 `-z` 选项时,不会保留文件的属性,因此目标文件可能不会保留与源文件完全相同的属性。
- 不执行递归复制:使用 `-z` 选项时,不会执行递归复制,只会复制指定的文件或目录,而不包括子目录和文件。
# 问题记录
1. failed to create pid file /var/run/rsyncd.pid: File exists
> 问题原因, 使用如下命令启动后, 再次启动报错 pid 已存在
>
> ```bash
> rsync --daemon --config=/etc/rsyncd.conf
> ```
解决方案
```bash
rm -rf /var/run/rsyncd.pid
```

View File

@@ -0,0 +1,52 @@
> 本文作者:丁辉
# Rsync常用参数解释
## Rsync 常用参数解释
-avz这是一组选项分别代表
- `-a`:表示"归档"模式,用于保留文件的所有属性,包括权限、所有者、组、时间戳等等。
- `-v`:表示"详细"模式,用于在执行时显示更多详细信息。
- `-z`:表示启用压缩传输,将文件在传输过程中进行压缩,以减少网络带宽的使用。
- -P这是 --partial --progress 的缩写,启用了两个有用的选项:
- `--partial`:如果传输被中断,保留部分传输的文件,以便下次传输时可以继续。
- `--progress`:在终端显示传输进度信息,包括已传输的数据量和估计剩余时间。
- `-r`:递归复制子目录和文件。
- `--delete`:这个选项表示在目标目录中删除那些在源目录中不存在的文件。这意味着目标目录将与源目录保持同步,不会有多余的文件留在目标目录中。
## Rsync 配置文件参数
全局参数
| 参数 | 含义 | 写法 |
| :----------------: | :----------------------------------------------------------: | :--------------------------------------------------------: |
| uid | 指定Rsync进程中使用的用户的用户标识 | uid = nobody |
| gid | 指定Rsync进程中使用的用户组的组标识 | gid = nobody |
| timeout | 定义客户指定的 IP 超时时间 | timeout = 600 |
| transfer logging | 启用传输日志记录 | transfer logging = yes |
| ignore nonreadable | 告诉 Rsync 忽略无法读取的文件 | ignore nonreadable = yes |
| dont compress | 指定不需要进行压缩的文件类型列表 | dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 |
| port | 指定守护进程监听的端口号 | port = 873 |
| log file | 指定守护进程的日志文件 | log file = /var/log/rsyncd.log |
| pid file | 指定 PID 写入文件路径和名称 | pid file = /var/run/rsyncd.pid |
| lock file | 指定锁文件的路径和名称 | lock file = /var/run/rsyncd.lock |
| max connections | 定义了可以同时处理的最大连接数 | max connections = 4 |
| list | 这个参数用于控制是否允许列出Rsync服务器上的文件和目录 | list = false |
| fake super | 当启用时Rsync会在备份文件的目标位置创建一个特殊的目录通常是`.rsync`),用于存储元数据和权限信息。这可以确保备份数据的权限等信息得以保留,即使目标位置的用户没有足够的权限 | fake super = yes |
| use | 控制是否启用chrootChange Root机制 | use chroot = no |
| ignore errors | 忽略错误 | ignore errors |
模块参数
| 参数 | 含义 | 写法 |
| :----------: | :---------------------------------------------------: | :----------------------------------: |
| path | Rsync服务器要同步的目录的路径 | path=/data |
| comment | 描述信息 | comment = backup data |
| hosts deny | 指定了一个IP地址范围不允许访问Rsync服务器的主机的IP地 | hosts deny = 192.168.1.0/24 |
| hosts allow | 指定了一个特定的IP地址允许访问Rsync服务器的主机的IP地 | hosts allow = 192.168.1.0/24 |
| auth users | 指定了哪个用户可以通过Rsync进行身份验证并访问服务器 | auth users = rsync |
| secrets file | Rsync服务器将使用这个文件来验证用户的身份 | secrets file = /etc/rsync_salve.pass |
| read only | 设置Rsync服务器的只读权限 | read only = no |
| exclude | 排除(不同步)的文件或文件夹的名称 | exclude=demo |

37
存储/磁盘清理.md Normal file
View File

@@ -0,0 +1,37 @@
> 本文作者:丁辉
# 磁盘清理
- Wipefs 清理
```bash
wipefs -af /dev/sdb
```
- **`wipefs`**: 这是一个用于清除存储设备上的文件系统、RAID 或分区表标记(如 NTFS、FAT、EXT4 等)的命令。它可以使设备“空白”,但不会销毁设备内的数据。
- **`-a`**: 这个选项指示 `wipefs` 清除所有可识别的标记类型。这是确保从设备中删除所有已识别的文件系统和卷标记的一种方式。
- **`-f`**: 这个选项强制执行删除操作,不需要对每个删除操作进行确认。这使得过程不需交互,适用于脚本或其他自动化环境中。
- Dd 清理
- 将前100MB的磁盘空间写为零这可能用于快速清除磁盘的开始部分常见于需要删除分区表或启动信息的场景。
```bash
dd if=/dev/zero of=/dev/sdb bs=1M count=100
```
- 将磁盘上原有的数据被彻底删除,常用于数据隐私保护。
```bash
dd if=/dev/zero of=/dev/sdb bs=1M status=progress
```
- Sgdisk 清理
```bash
sgdisk -Z -g /dev/sdb
```
- `sgdisk`: 这是一个用于处理GPTGUID Partition Table分区表的命令行工具。
- `-Z`: 这个选项用于清除所有分区的备份GPTGUID Partition Table
- `-g`: 这个选项用于生成一个空的GPT分区表。

View File

@@ -0,0 +1,23 @@
> 本文作者:丁辉
# 设备或资源繁忙
## 块设备资源繁忙
> mkfs.xfs: cannot open /dev/sdb: Device or resource busy
解决办法
1. 列出所有逻辑设备
```bash
dmsetup ls
```
2. 移除占用
```bash
dmsetup remove ${逻辑设备}
```