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

83
.drone.yml Normal file
View File

@@ -0,0 +1,83 @@
# kubectl create secret generic build-node-secret \
# --from-literal=HOST="" \
# --from-file=KEY=./*.pem \
# --from-literal=PORT="22" \
# --from-literal=PATH="" \
# --namespace=drone
kind: pipeline
type: kubernetes
name: MD BUILD
trigger:
event:
include:
- custom
workspace:
base: /drone/
path: /drone/Linux
steps:
- name: 编译文档正文
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:ubuntu-22.04
pull: if-not-exists
commands:
- ./builder.sh
- rm -rf ./builder.sh
- name: 生产环境部署
image: appleboy/drone-scp
pull: if-not-exists
settings:
host:
from_secret: HOST
key:
from_secret: KEY
port:
from_secret: PORT
target:
from_secret: PATH
user: root
source: ../Linux
overwrite: true
- name: 重启生产博客组件
image: registry.cn-hangzhou.aliyuncs.com/offends/drone:ubuntu-22.04
volumes:
- name: kubectl
path: /usr/local/bin
- name: config
path: /root/.kube
commands:
- /usr/local/bin/kubectl -n blog rollout restart deployment blog
volumes:
- name: kubectl
host:
path: /usr/local/bin
type: File
- name: config
host:
path: /root/.kube
---
kind: secret
name: HOST
get:
path: build-node-secret
name: HOST
---
kind: secret
name: KEY
get:
path: build-node-secret
name: KEY
---
kind: secret
name: PORT
get:
path: build-node-secret
name: PORT
---
kind: secret
name: PATH
get:
path: build-node-secret
name: PATH

28
.gitignore vendored Normal file
View File

@@ -0,0 +1,28 @@
# ---> macOS
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

View File

@@ -0,0 +1,12 @@
> 本文作者:丁辉
# APT清理无用软件包
清理无用软件包
```bash
apt autoremove
```
> `apt autoremove` 是一个用于在Ubuntu和其他基于Debian的Linux系统上管理软件包的命令。它的主要目的是删除不再被其他软件包所依赖的已安装软件包以便释放磁盘空间并保持系统干净。

View File

@@ -0,0 +1,68 @@
> 本文作者:丁辉
# Centos-Devtoolset升级Gcc
> 命令行升级方式无需[源码编译](https://ftp.gnu.org/gnu/gcc/)
1. 安装 centos-release-scl
```bash
yum install centos-release-scl -y
```
2. 安装 devtoolset
> 查看版本
>
> ```bash
> yum list devtoolset*
> ```
>
> 可安装多个版本切换使用
```bash
yum install devtoolset-11-gcc*
```
3. 启动 devtoolset
```bash
scl enable devtoolset-11 bash
```
4. 查看版本
```bash
gcc -v
```
5. 切换版本
> 脚本目录在 `/opt/rh/devtoolset-*/enable`
```bash
source /opt/rh/devtoolset-10/enable
```
6. 彻底替换旧的 Gcc, 移除旧的版本
```bash
mv /usr/bin/gcc /usr/bin/gcc.bak
mv /usr/bin/g++ /usr/bin/g++.bak
```
7. 创建新的软连接
```bash
ln -s /opt/rh/devtoolset-11/root/bin/gcc /usr/bin/gcc
ln -s /opt/rh/devtoolset-11/root/bin/g++ /usr/bin/g++
```
8. 查看版本
```bash
gcc --version
g++ --version
```

View File

@@ -0,0 +1,31 @@
> 本文作者:丁辉
# Centos7更换阿里源
1. 备份本地Yum源
```bash
mkdir -p /etc/yum.repos.d/backup/
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
```
2. 下载阿里云Yum源
```bash
curl -O http://mirrors.aliyun.com/repo/Centos-7.repo
curl -O http://mirrors.aliyun.com/repo/epel-7.repo
```
3. *删除缓存数据*
```bash
yum clean all
```
4. *创建元数据缓存*
```bash
yum makecache
```

View File

@@ -0,0 +1,97 @@
> 本文作者:丁辉
# Centos安装Python
## Python安装
> 前提条件:
>
> - 升级 Openssl 版本, 至少 OpenSSL 1.1.1 [OpenSSL源码编译升级](https://gitee.com/offends/Docs/blob/main/Linux/%E5%AE%89%E8%A3%85OpenSSL.md)
[Python源码包下载](https://www.python.org/ftp/python/)
1. 下载源码包
```bash
wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tgz
```
2. 解压源码包
```bash
tar -zxvf Python-*.tgz && cd cd Python-*
```
3. 安装编译所需的依赖
```bash
# 软件包组通常包含用于软件开发和编译的工具如编译器、调试器、make工具等。
yum groupinstall "Development Tools" -y
yum install openssl-devel bzip2-devel libffi-devel -y
```
4. 配置编译项
```bash
./configure -q --with-openssl=/usr/local/openssl --prefix=/usr/local/python3.10.13 --with-openssl-rpath=auto --enable-optimizations
```
**参数解释**
| 参数 | 描述 |
| :---------------------------------: | :----------------------------------------------------------: |
| `--with-openssl=/usr/local/openssl` | 指定OpenSSL库的安装位置。这对于编译需要OpenSSL支持的软件如Python中的_ssl模块非常重要。这里指的是OpenSSL安装在`/usr/local/openssl`目录下。 |
| `--prefix=/usr/local/python3.10.13` | 指定安装目标目录。这意味着所有安装的文件(包括可执行文件、库文件等)将被放置在`/usr/local/python3.10.13`目录下。这有助于避免与系统自带的Python版本冲突并方便管理不同版本的Python。 |
| `--with-openssl-rpath=auto` | 设置运行时链接器搜索OpenSSL库的路径为自动。这确保了在运行时能够找到正确的OpenSSL库即使它不在标准库路径下。这对于确保程序能够在不同环境中正确运行非常重要。 |
| `--enable-optimizations` | 启用额外的优化比如Profile Guided OptimizationPGO以提高Python的性能。这会增加编译时间但生成的Python解释器将运行得更快特别是对于一些计算密集型的任务。 |
| `-q` | 这个参数表示“quiet”的意思即在执行过程中尽量减少输出信息只有重要或必要的信息会被显示出来。 |
5. 开始编译
```bash
make
```
> 同时运行
>
> ```bash
> make -j 4
> ```
6. 安装
```bash
make altinstall
```
> altinstall避免替换默认的系统Python版本
7. 创建软连接
```bash
ln -s /usr/local/python3.10.13/bin/python3.10 /usr/local/bin/
```
8. 验证
```bash
python3.10 --version
```
9. 验证 ssl 模块
```bash
python3.10
```
输入
```bash
import ssl
ssl.OPENSSL_VERSION
```
## 问题记录
- make 遇到 Could not import runpy module 需要升级 PIP 版本即可解决

View File

@@ -0,0 +1,47 @@
> 本文作者:丁辉
# Centos配置本地Yum源
1. 进入目录
```bash
cd /etc/yum.repos.d/
```
2. 移走其他文件
```bash
mkdir /opt/yum
mv * /opt/yum
```
3. 创建文件并编写内容
```bash
vi yum.repo
```
内容如下
```bash
[name]
name=yum
baseurl=file:///mnt/
gpgcheck=0
enabled=1
```
4. 挂载镜像DVD
```bash
mount /dev/cdrom /mnt/
```
5. 清理缓存
```bash
yum clean all
yum makecache
```

View File

@@ -0,0 +1,47 @@
> 本文作者:丁辉
# Centos重置Root密码
1. 重启服务器在选取内核界面按 `e`
<img src="https://minio.offends.cn:9000/offends/images/image-20240706142021741.png">
2. 找到以 `linux16` 开头的行添加如下内容
<img src="https://minio.offends.cn:9000/offends/images/image-20240706142326298.png">
3.`Ctrl+x` 保存
4. 进入系统后执行挂载 / 文件系统
```bash
mount -o remount, rw /
```
<img src="https://minio.offends.cn:9000/offends/images/image-20240706142853583.png">
5. 重置密码(密码不能过于简单)
```bash
passwd root
```
<img src="https://minio.offends.cn:9000/offends/images/image-20240706143013863.png">
6. 创建此文件让系统启动全盘的 SELinux 上下文重新标记
```bash
touch /.autorelabel
```
<img src="https://minio.offends.cn:9000/offends/images/image-20240706143459451.png">
7. 重启 init 进程让系统恢复到正常的多用户运行级别
```bash
exec /sbin/init
```
8. 登录新密码测试

69
Docs/Iptables限制.md Normal file
View File

@@ -0,0 +1,69 @@
> 本文作者:丁辉
# Iptables限制
> 80端口举例
- 禁止
```bash
iptables -I INPUT -p tcp -m multiport --dport 80 -j DROP
```
```bash
iptables -I DOCKER -p tcp -m multiport --dport 80 -j DROP
```
- 指定IP允许访问
```bash
iptables -I INPUT -m iprange --src-range 192.168.1.1-192.168.1.2 -p tcp -m multiport --dport 80 -j ACCEPT
```
```bash
iptables -I DOCKER -m iprange --src-range 192.168.1.1-192.168.1.2 -p tcp -m multiport --dport 80 -j ACCEPT
```
- 指定某网段允许访问
```bash
iptables -I INPUT -s 192.168.1.0/24 -p tcp -m multiport --dport 80 -j ACCEPT
```
```bash
iptables -I DOCKER -s 192.168.1.0/24 -p tcp -m multiport --dport 80 -j ACCEPT
```
- 查看规则
```bash
iptables -nL INPUT --line-numbers
iptables -nL DOCKER --line-numbers
```
- 删除规则
```bash
iptables -D INPUT 1
iptables -D DOCKER 1
```
- 持久化
```bash
iptables-save > /etc/sysconfig/iptables
```
```bash
vim /etc/rc.d/rc.local
iptables-restore < /etc/sysconfig/iptables
chmod +x /etc/rc.d/rc.local
```
假设您想要添加一条优先级为 1 的 INPUT 链规则,可以使用以下命令:
> 数字越小,优先级越高
```bsah
iptables -I INPUT 1 <规则内容>
```

View File

@@ -0,0 +1,100 @@
> 本文作者丁辉
# Linux下载并安装GPU驱动
[NVIDIA中文官方驱动下载页面](https://www.nvidia.cn/Download/index.aspx?lang=cn)
## GPU驱动下载
1. 查看显卡型号
```bash
lspci | grep -i nvidia
# 或
lspci | grep -i vga
```
结果
```bash
[root@offends ~]# lspci | grep -i nvidia
00:08.0 3D controller: NVIDIA Corporation TU104GL [Tesla T4] (rev a1)
```
2. 根据自己的显卡型号去下载驱动
- Product TypeTesla
- Product SeriesT
- ProductT4
- Operating SystemLinux 64-bit
- CUDA ToolkitAny
- LanguageChinese (Traditional)
```bash
wget https://cn.download.nvidia.com/tesla/440.95.01/NVIDIA-Linux-x86_64-440.95.01.run
```
3. 部署
```bash
bash NVIDIA-Linux-x86_64-*.run
```
4. 测试效果
```bash
nvidia-smi
```
结果
```bash
[root@offends ~]#
Mon Oct 2 16:22:37 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.106.00 Driver Version: 460.106.00 CUDA Version: 11.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 Tesla T4 On | 00000000:00:08.0 Off | 0 |
| N/A 30C P8 9W / 70W | 0MiB / 15109MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
```
## Linux 卸载 NVIDIA 驱动
- 有部署文件情况下
```bash
bash NVIDIA-Linux-x86_64-*.run --uninstall
```
- 没有原部署文件的情况下
```bash
/usr/bin/nvidia-uninstall
```
## 问题记录
- 经过多次卸载安重新装遇到报错
```bash
ERROR: An NVIDIA kernel module 'nvidia' appears to already be loaded in your kernel. This may be because it is in use (for example, by an X server, a CUDA program, or the NVIDIA Persistence Daemon), but this may also happen
if your kernel was configured without support for module unloading. Please be sure to exit any programs that may be using the GPU(s) before attempting to upgrade your driver. If no GPU-based programs are running, you
know that your kernel supports module unloading, and you still receive this message, then an error may have occured that has corrupted an NVIDIA kernel module's usage count, for which the simplest remedy is to reboot
your computer.
```
**解决方法直接 `reboot` 重启服务器解决成功率 99% 哈哈**

View File

@@ -0,0 +1,50 @@
> 本文作者:丁辉
# Linux中如何让目录和文件不能被删除
## 如何让文件不能删除
1. 创建文件
```bash
touch offends.sh
```
2. 添加文件属性
```bash
sudo chattr +i offends.sh
sudo chattr +i -V offends.sh
```
3. 查看文件属性
```bash
lsattr offends.sh
```
> 恢复
>
> ```bash
> sudo chattr -i offends.sh
> ```
## 如何让目录不能删除
1. 创建目录
```bash
mkdir offends
```
2. 添加目录属性
```bash
sudo chattr +i -RV offends/
```
> 恢复
>
> ```bash
> sudo chattr -i -RV offends/
> ```

169
Docs/Linux内核升级.md Normal file
View File

@@ -0,0 +1,169 @@
> 本文作者:丁辉
# Linux内核升级
## Centos-内核升级
### 网络升级
#### 升级内核
[ELRepo官网](http://elrepo.org/tiki/HomePage)
[官方内核rpm包](http://elrepo.reloumirrors.net/kernel/)
[国内内核包源](https://mirrors.tuna.tsinghua.edu.cn/kernel/)
1. 载入公钥
```bash
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
```
2. 安装 ELRepo 源
- Http
```bash
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
```
- Https
```bash
rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
```
3. 查看可用的 kernel 包
- 检查已启用的存储库列表
```bash
yum repolist
```
- 将所有已启用的仓库禁用,然后仅启用 `elrepo-kernel` 仓库
```bash
yum list available --disablerepo='*' --enablerepo=elrepo-kernel
```
**版本介绍**
| 版本 | 解释 |
| :-----------------: | :----------------------------------------------------------: |
| LT (Long Term) 版本 | Long Term 版本是指 Linux 内核的长期支持版本。这些版本经过仔细测试和稳定性验证,通常会在发布后获得较长时间的支持和更新,以提供更长的生命周期和稳定性保证。对于企业和组织而言,使用 LT 版本可以获得持续的安全修复、错误修复和功能改进,而无需频繁地进行升级。 |
| ML (Mainline) 版本 | Mainline 版本是指 Linux 内核的主线发行版即最新的稳定版本。这些版本包含最新的功能、驱动程序和改进并经过广泛测试和社区接受。Mainline 版本往往具有更先进的特性和性能,但可能在某些情况下会存在一些不稳定性或兼容性问题。因此,它们一般适合于技术爱好者、开发人员和那些需要最新功能和改进的用户。 |
> 总结来说LT (Long Term) 版本提供了长期支持和稳定性,适用于那些更注重稳定性和可靠性的用户和组织;而 ML (Mainline) 版本则提供了最新的功能和改进,适用于那些寻求最新特性和技术的用户。
4. 安装最新版本的kernel-lt 版本
```bash
yum --enablerepo=elrepo-kernel install kernel-lt -y
```
5. 查看内核插入顺序
```bash
awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
```
6. 设置默认启动
```bash
grub2-set-default 0
```
7. 查看当前实际启动顺序
```bash
grub2-editenv list
```
8. 重启检查
```bash
reboot
```
#### 删除旧版本内核
- 直接卸载
```bash
yum remove $(rpm -q kernel | grep 3.10) -y
```
- 当内核数量超过三个时可以使用此命令清理
1. 安装软件包
```bash
yum install yum-utils
```
2. 清理
```bash
package-cleanup --oldkernels
```
### 离线安装
> 在有网环境通过上面的方法添加源后下载 rpm 文件
1. 创建目录
```bash
mkdir /root/kernel/
```
2. 拉取文件
```bash
yumdownloader --enablerepo=elrepo-kernel --resolve --destdir=/root/kernel/ kernel-lt
```
> 离线环境安装
1. 安装
```bash
yum localinstall -y kernel-*.rpm
```
> 后续依然是如上操作,直至重启验证
## Ubuntu-内核升级
### 包指定版本升级
[内核包官网下载](http://kernel.ubuntu.com/~kernel-ppa/mainline/)
1. 下载符合这两个格式的文件
```bash
linux-image-*-generic-*.deb
linux-modules-*-generic-*.deb
```
2. 执行安装命令
```bash
dpkg --install *.deb
```
3. 重启
```bash
reboot
```
4. 查看内核版本
```bash
uname -r
```

31
Docs/Linux安装桌面.md Normal file
View File

@@ -0,0 +1,31 @@
> 本文作者:丁辉
# Linux安装桌面
## Centos安装
1. 安装
```bash
yum groups install "X Window System"
yum groups install "MATE Desktop"
```
2. 修改默认使用图形化界面启动
```bash
systemctl set-default graphical.target
```
3. 重启服务器
```bash
reboot
```
## Ubuntu安装
```bash
apt install ubuntu-desktop
```

View File

@@ -0,0 +1,134 @@
> 本文作者:丁辉
# Linux开启远程桌面连接
## 安装 xrdp
**xrdp (X Remote Desktop Protocol)介绍**
xrdp 是一个远程桌面服务器,允许远程用户通过 Microsoft 的 RDPRemote Desktop Protocol协议连接到 Linux 系统的图形桌面环境。xrdp 提供了一种方式,使 Windows 和其他支持 RDP 的操作系统用户能够通过 RDP 客户端连接到 Linux 桌面。安装和配置 xrdp 通常涉及安装 xrdp 软件包,并确保 xrdp 服务在后台运行。用户连接时xrdp 将会启动用户指定的桌面环境。
1. 安装依赖
```bash
yum install epel-release -y
```
2. 安装 xrdp
```bash
yum install xrdp -y
```
3. 启动
```bash
systemctl enable xrdp && systemctl start xrdp
```
4. Windows 按住键盘上的 win + R 输入 `mstsc` 输入IP 地址 + 3389 连接
## 安装 tigervnc
```bash
yum install tigervnc-server -y
```
> **TigerVNC (Tiger Virtual Network Computing)介绍**
>
> TigerVNC 是一个实现 VNCVirtual Network Computing协议的远程桌面工具允许用户通过网络连接到远程计算机的图形界面。与 xrdp 不同TigerVNC 并不是为特定的远程桌面协议设计的。它可以与各种 VNC 客户端一起使用,无论是基于 Windows、Linux 还是其他操作系统的。安装和配置 TigerVNC 通常涉及安装 TigerVNC 软件包,然后配置 VNC 服务器以便用户能够连接。
- 启动 vncserver
```bash
vncserver
```
- 查看
```bash
vncserver -list
```
- 删除
```bash
vncserver -kill :1
```
### 下载 VNC 连接工具
[RealVNC下载地址](https://www.realvnc.com/en/connect/download/vnc/)
连接地址为: IP + 端口 启动时配置的密码
```bash
192.168.1.100:1
```
# Ubuntu开启远程桌面连接
## 安装 xrdp
**xrdp (X Remote Desktop Protocol)介绍**
xrdp 是一个远程桌面服务器,允许远程用户通过 Microsoft 的 RDPRemote Desktop Protocol协议连接到 Linux 系统的图形桌面环境。xrdp 提供了一种方式,使 Windows 和其他支持 RDP 的操作系统用户能够通过 RDP 客户端连接到 Linux 桌面。安装和配置 xrdp 通常涉及安装 xrdp 软件包,并确保 xrdp 服务在后台运行。用户连接时xrdp 将会启动用户指定的桌面环境。
1. 安装 xrdp
```bash
apt install xrdp -y
```
2. 启动
```bash
systemctl enable xrdp && systemctl start xrdp
```
3. Windows 按住键盘上的 win + R 输入 `mstsc` 输入IP 地址 + 3389 连接
## 安装 tigervnc
```bash
apt-get install tigervnc-standalone-server tigervnc-xorg-extension
```
> **TigerVNC (Tiger Virtual Network Computing)介绍**
>
> TigerVNC 是一个实现 VNCVirtual Network Computing协议的远程桌面工具允许用户通过网络连接到远程计算机的图形界面。与 xrdp 不同TigerVNC 并不是为特定的远程桌面协议设计的。它可以与各种 VNC 客户端一起使用,无论是基于 Windows、Linux 还是其他操作系统的。安装和配置 TigerVNC 通常涉及安装 TigerVNC 软件包,然后配置 VNC 服务器以便用户能够连接。
- 启动 vncserver
```bash
vncserver
```
- 查看
```bash
vncserver -list
```
- 删除
```bash
vncserver -kill :1
```
### 下载 VNC 连接工具
[RealVNC下载地址](https://www.realvnc.com/en/connect/download/vnc/)
连接地址为: IP + 端口 启动时配置的密码
```bash
192.168.1.100:1
```

View File

@@ -0,0 +1,63 @@
> 本文作者:丁辉
# Linux更换国内源
[阿里镜像站](https://developer.aliyun.com/mirror/)
## Centos更换国内源
- Centos7
```bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
```
## Ubuntu更换国内源
- 新版
```bash
sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
```
- 旧版
```bash
#中国科技大学
sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
#网易云163
sed -i 's/deb.debian.org/mirrors.163.com/g' /etc/apt/sources.list
#阿里云
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
#清华同方
sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
```
- ARM版
```bash
sed -i 's/ports.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
```
## Alpine更换国内源
- 阿里云源
```bash
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
```
- 中国科技大学的源
```bash
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
```
- 清华源
```bash
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
```

View File

@@ -0,0 +1,46 @@
> 本文作者:丁辉
# Linux更改时区为24小时
1. 首先更改时区
```bash
rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
```
2. 更改时区为24小时
- Centos 更改时区为24小时
```bash
vi /etc/locale.conf
```
内容如下
```bash
LANG="zh_CN.UTF-8"
# LANG="en_US.UTF-8"
```
- Ubuntu 更改时区为24小时
```bash
vi /etc/default/locale
```
内容如下
```bash
LANG="zh_CN.UTF-8"
# LANG="en_US.UTF-8"
```
3. 重启服务器完成
```bash
reboot
```

View File

@@ -0,0 +1,52 @@
> 本文作者:丁辉
# Linux更改时间和时区
**查看时间**
```bash
date -R
```
## 更改系统时间
- 手动更改
```bash
date -s "2024-04-04 04:44:44"
```
- Ntpdate 同步
```bash
# 同步阿里云时间服务器
ntpdate ntp1.aliyun.com
```
> 遇到报错 `the NTP socket is in use, exiting` , 停止 Ntpd 服务解决
>
> ```bash
> systemctl stop ntpd
> ```
## 更改时区
> 示例修改时区到 Asia/Shanghai
- 手动更改
```bash
rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
```
- 使用 Timedatectl 更改
```bash
timedatectl set-timezone Asia/Shanghai
```
- 使用 Tzselect 更改
```bash
tzselect
```

View File

@@ -0,0 +1,39 @@
> 本文作者:丁辉
# Linux查看CPU信息
- 查看全部信息
```bash
cat -n /proc/cpuinfo
```
- 查看物理 CPU 的个数
```bash
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
```
> 注意:物理 CPU 就是实实在在的硬件
或使用 `nproc` 和 `lscpu`
- 查看逻辑 CPU 的个数
```bash
cat /proc/cpuinfo | grep "processor" | wc -l
```
- 查看 CPU 是几核
```bash
cat /proc/cpuinfo | grep "cores" | uniq
```
- 查看 CPU 的主频
```bash
cat /proc/cpuinfo | grep MHz | uniq
```

View File

@@ -0,0 +1,17 @@
> 本位作者:丁辉
# Linux查看内核日志
- 访问 systemd 管理的日志 `--no-pager` 代表自动换行
```bash
journalctl -xe --no-pager
```
- 显示内核环缓冲区的内容
```bash
dmesg
```

View File

@@ -0,0 +1,10 @@
> 本文作者:丁辉
# Linux清理僵尸进程
> 使用 top 命令查看 zombie 代表为僵尸进程的数量
```bash
ps -A -o stat,ppid,pid,user,cmd | grep -e '[Zz]' | awk '{print $2}' | xargs kill
```

26
Docs/Linux清理缓存.md Normal file
View File

@@ -0,0 +1,26 @@
> 本文作者:丁辉
# Linux清理缓存
Linux 系统有三种选项来清除缓存而不需要中断任何进程或服务。
> 译注Cache译作“缓存”指 CPU 和内存之间高速缓存。Buffer译作“缓冲区”指在写入磁盘前的存储再内存中的内容。在本文中Buffer 和 Cache 有时候会通指。)
- 仅清除页面缓存PageCache
```bash
sync; echo 1 > /proc/sys/vm/drop_caches
```
- 清除目录项和inode
```bash
sync; echo 2 > /proc/sys/vm/drop_caches
```
- 清除页面缓存目录项和inode
```bash
sync; echo 3 > /proc/sys/vm/drop_caches
```

View File

@@ -0,0 +1,162 @@
> 本文作者:丁辉
# Linux用户和组配置
> 常用命令
查询当前用户
```bash
whoami
```
## linux 创建用户,群组,权限
- 创建用户
```bash
useradd demo
```
- 创建群组
```bash
groupadd demo
```
- 修改用户账户
```bash
usermod
```
| 参数 | 解释 |
| :--: | :----------------------------------------- |
| -l | 用户重命名 (用户家目录名需要手动修改) |
| -g | 修改用户所在的群组 |
| -G | 将用户添加到多个群组(群组之间,用逗号隔开) |
| -a | 追加 |
- 删除用户
```bash
userdel demo
```
> `-r` 选项会删除用户的主目录及其内容。
- 删除群组
```bash
groupdel demo
```
- 改变文件的所有者
```bash
chown
```
> -R参数递归设置子目录和子文件 (R 只能是大写,小写不起作用)
> 假如想要把用户demo的家目录的所有子目录和文件一起修改
```bash
chown -R demo:demo /home/demo
```
> 则/home/demo都归我(demo)所有了
- 改变文件的群组
```bash
chgrp
```
> chown命令可以改变文件的群组
```bash
chown demo:root demo.txt
```
> 就是把file.txt文件的所有者改为demo ,群组改为 root
- 修改访问权限
```bash
chmod
```
- 查看访问权限
```bash
ls -l
```
> 文件信息较复杂可看到d,w,r,l,x等字母。不细分的话这些可以通称为 文件访问权限符。
| 字符 | 含义 |
| ---- | -------- |
| d | 目录 |
| l | 链接 |
| u | 所有者 |
| g | 群组用户 |
| o | 其他用户 |
| a | 所有用户 |
| + | 添加权限 |
| - | 移除权限 |
| = | 分配权限 |
例如:
```bash
chmod u+rx file #文件file的所有者增加可读可执行的权限
chomd g +r file #文件file的群组用户增加可读的权限
chmod o-r file #文件file的其他用户移除可读的权限
chmod g+r o-r file #文件 file 的群组用户增加可读的权限,其他用户移除可读的权限
chmod go-r file #文件file 的群组用户,其他用户均移除可读的权限
chmod +r file #文件file的所有的用户都增加可读的权限
chmod u=rwx,g=r,o=- file #文件 file的所有者分配可读可写可执行的权限群组分配可读的权限其他用户没有权限。
```
## linux给用户添加root权限
1. 添加用户, 并添加密码
```bash
useradd demo
passwd demo
```
2. 赋予root权限
**方法一**
- 修改 /etc/sudoers 文件, 解除注释
```bash
%wheel ALL=(ALL) ALL
```
- 然后修改用户, 使其属于root组wheel
```bash
usermod -g root demo
```
**方法二**
- 修改 /etc/sudoers 文件, 添加内容
```bash
demo ALL=(ALL) ALL
```
**方法三**
- 修改 /etc/passwd 文件把用户ID修改为 0
```bash
demo:x:0:500:demo:/home/demo:/bin/bash
```

View File

@@ -0,0 +1,17 @@
> 本文作者:丁辉
# Linux禁用Su权限
1. 修改配置文件
```bash
vi /etc/pam.d/su
```
2. 添加如下内容
```bash
auth required pam_succeed_if.so user != root quiet
```

View File

@@ -0,0 +1,59 @@
> 本文作者:丁辉
# Linux触发软重启
## 使用 SysRq 触发软重启
> 这个操作会立刻让系统重新启动,跳过正常的关机流程,包括运行关机脚本和同步磁盘等,所以在使用前确保所有重要数据已经保存。
1. 启用 SysRq 功能
> 默认情况下出于安全考虑SysRq 功能可能被部分或完全禁用。可以通过以下命令启用所有 SysRq 功能
```bash
echo 1 > /proc/sys/kernel/sysrq
```
2. 触发重启
> 通过向 `/proc/sysrq-trigger` 写入 `b` 来触发立即重启
```bash
echo b > /proc/sysrq-trigger
```
### 注意事项:
- **数据丢失**:使用 SysRq 功能触发的软重启相当于突然断电,可能导致未保存的数据丢失和文件系统损坏。
- **安全风险**:开启 SysRq 功能可能会带来安全风险,因为任何拥有物理访问权限的人都可能使用这个功能。
## 使用 kexec 重启内核的步骤如下:
1. 安装 kexec 工具
```bash
apt-get install kexec-tools
```
2. 加载新内核
> 使用 kexec 命令加载你想要启动的新内核。你需要指定内核文件和对应的初始化内存盘initrd和内核参数。
> 这里的 `/path/to/vmlinuz` 和 `/path/to/initrd.img` 需要替换为实际的文件路径。`root=/dev/sda1 ro quiet` 是内核启动参数,需要根据实际情况进行调整。
```bash
kexec -l /path/to/vmlinuz --initrd=/path/to/initrd.img --append="root=/dev/sda1 ro quiet"
```
3. 触发快速重启
> 这将跳过 BIOS/UEFI 初始化和硬件检测,直接启动新的内核。
```bash
kexec -e
```
### 注意事项:
- **数据丢失风险**:使用 kexec 重启内核,类似于正常重启,所有未保存的数据都可能丢失。确保在执行此操作前保存所有重要数据。
- **环境影响**:这种重启方式不会重新初始化硬件设备,某些由硬件状态异常引起的问题可能不会被解决。
- **兼容性和支持**:并非所有的 Linux 发行版都默认支持 kexec可能需要核实你的系统环境和内核配置。

71
Docs/Linux部署Minio.md Normal file
View File

@@ -0,0 +1,71 @@
> 本文作者:丁辉
# Linux部署Minio
## 开始部署
[Minio下载](https://dl.min.io/)
1. 下载二进制文件
```bash
wget https://dl.min.io/server/minio/release/linux-amd64/minio
```
2. 赋予权限并移动到可执行目录下
```bash
chmod +x minio && mv minio /usr/local/bin/
```
3. 创建数据目录
```bash
mkdir /opt/minio-data/
```
4. 启动 Minio
```bash
nohup minio server --address :9000 --console-address :9001 /opt/minio-data/ > /opt/minio-data/minio.log &
```
5. 登录
账户密码: minioadmin/minioadmin
## 使用 System 启动
1. 编辑 Service 文件
```bash
vim /etc/systemd/system/minio.service
```
内容如下
```bash
[Unit]
Description=Minio Service
[Service]
# Environment="MINIO_ROOT_USER=minioadmin"
# Environment="MINIO_ROOT_PASSWORD=minioadmin"
ExecStart=/usr/local/bin/minio server /root/minio-data/ --console-address ":9001"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
StandardOutput=/var/log/minio/minio.log
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```
2. 启动 Minio
```bash
systemctl daemon-reload
systemctl start minio.service
```

View File

@@ -0,0 +1,123 @@
> 本文作者:丁辉
# Minio-Mc工具使用
## 安装 MC 工具
[下载地址](https://dl.min.io/client/mc/release/)
**下载并安装**
```bash
wget https://dl.min.io/client/mc/release/linux-amd64/mc && chmod 777 mc && mv mc /usr/local/bin/
```
## 配置 Minio 信息
**配置 MC**
```bash
mc config host add minio https://localhost:9000 MINIO_ACCESS_KEY MINIO_SECRET_KEY
```
> 配置格式
>
> ```bash
> mc config host add <命名> <Minio地址> <AccessKey 或 账号> <SecretKey 或 密码>
> ```
## MC 使用基础命令
- 查看主机配置信息
```bash
mc config host list minio
```
- 删除主机信息
```bash
mc config host remove minio
```
> 可使用如下命令查看主机列表
>
> ```bash
> mc config host list
> ```
- 查看存储文件
```bash
mc ls minio
```
- 创建存储桶
```bash
mc mb minio/<桶>
```
> 递归创建存储桶
>
> ```bash
> mc mb minio/<桶>/...
> ```
- 删除
- 删除文件
```bash
mc rm minio/<桶>/<文件>
```
- 删除目录
```bash
mc rm minio/<桶>/<目录>
```
> 强制删除有文件的目录添加参数 `--recursive --force`
- 删除桶
```bsah
mc rb minio/<桶>
```
>如果桶内咳存在文件, 强制删除添加参数 `--force`
- 配置存储通访问权限
- 查看访问权限
```bash
mc anonymous list minio/<桶>
```
- 公共
```bash
mc anonymous set public minio/<桶>
```
- 查看存储空间
```bash
mc du minio/<桶>
```
- 拷贝文件
```bash
mc cp ./<本地文件> minio/<桶>
```
- 以文件树结构列出内容
```bash
mc tree minio/<桶>
```

28
Docs/NPM加速配置.md Normal file
View File

@@ -0,0 +1,28 @@
> 本文作者:丁辉
# NPM加速配置
- 淘宝镜像源
```bash
npm config set registry https://registry.npm.taobao.org
```
验证
```bash
npm config get registry
```
- 华为云镜像源
```bash
npm config set registry https://mirrors.huaweicloud.com/repository/npm/
```
验证
```bash
npm config get registry
```

97
Docs/NTP时间同步.md Normal file
View File

@@ -0,0 +1,97 @@
> 本文作者:丁辉
# NTP时间同步
| 节点名称 | IP |
| :-------------------: | :-----------: |
| ntp-master(NTP服务器) | 192.168.1.100 |
| node-1 | 192.168.1.10 |
| node-2 | 192.168.1.20 |
| node-3 | 192.168.1.30 |
## 基础环境配置
**安装 ntp 服务**
- Centos
```bash
yum -y install ntp
```
- Ubuntu
```bash
apt -y install ntp
```
## NTP服务器配置
1. 修改配置文件
```bash
cp /etc/ntp.conf /etc/ntp.conf.bak
vi /etc/ntp.conf
```
修改配置文件内容如下
```bash
##server 0.centos.#pool.ntp.org iburst
##server 1.centos.#pool.ntp.org iburst
##server 2.centos.#pool.ntp.org iburst
##server 3.centos.#pool.ntp.org iburst
server 127.127.1.0
```
> 填写 127.127.1.0 是一个特殊的IP地址, 代表本地主机(即自己) 或 填写其他授时中心服务器地址
2. 启动 ntpd 服务
```bash
systemctl enable ntpd
systemctl start ntpd
```
## 其他节点同步 NTP 服务器时间
1. 修改配置文件
```bash
cp /etc/ntp.conf /etc/ntp.conf.bak
vi /etc/ntp.conf
```
修改配置文件内容如下
```bash
##server 0.centos.#pool.ntp.org iburst
##server 1.centos.#pool.ntp.org iburst
##server 2.centos.#pool.ntp.org iburst
##server 3.centos.#pool.ntp.org iburst
server 192.168.1.100
```
> 192.168.1.100 为 NTP 服务器 IP 地址
2. 启动 ntpd 服务
```bash
systemctl enable ntpd
systemctl start ntpd
```
3. 启动 ntpd 服务
```bash
systemctl enable ntpd
systemctl start ntpd
```
4. 查看状态
```bash
ntpq -p
```

View File

@@ -0,0 +1,67 @@
> 本文作者:丁辉
# OSS-Ossutil64工具使用
## 安装 Ossutil64 工具
[下载地址](https://github.com/aliyun/ossutil/releases)
[使用文档](https://help.aliyun.com/zh/oss/developer-reference/configure-ossutil)
**下载并安装**
```bash
curl https://gosspublic.alicdn.com/ossutil/install.sh | bash
```
## 配置 Ossutil64
[Endpoint对照表](https://help.aliyun.com/zh/oss/user-guide/regions-and-endpoints)
**配置 Ossutil64**
```bash
./ossutil64 config
```
> 配置格式
>
> ```bash
> The command creates a configuration file and stores credentials.
>
> # 指定配置文件的名称、路径(默认为 /root/.ossutilconfig按回车键将使用默
> Please enter the config file name,the file name can include path(default /root/.ossutilconfig, carriage return will use the default file. If you specified this option to other file, you should specify --config-file option to the file when you use other commands):
> No config file entered, will use the default config file /root/.ossutilconfig
>
> For the following settings, carriage return means skip the configuration. Please try "help config" to see the meaning of the settings
> # 配置语言(默认为 EN)。
> Please enter language(CH/EN, default is:EN, the configuration will go into effect after the command successfully executed):
> # STS 令牌Security Token Service Token用于临时授权访问阿里云资源。
> Please enter stsToken:
> # Access Key Secret是用于对称加密算法的密钥用于验证身份和进行访问控制。
> Please enter accessKeySecret:
> # 终端节点,通常指特定网络服务的网络地址,用于指示客户端如何连接到服务。
> Please enter endpoint:
> # Access Key ID用于标识阿里云账户或子账户的访问密钥。
> Please enter accessKeyID:
> ```
## Ossutil64 使用基础命令
- 查看桶文件
```bash
ossutil64 ls oss://
```
- 创建存储桶
```bash
ossutil64 mb oss://<桶>
```
- 拷贝文件
```bash
./ossutil64 cp ./<本地文件> oss://<桶>/
```

View File

@@ -0,0 +1,61 @@
> 本文作者:丁辉
# Parted分配磁盘
## 整块磁盘分配挂载
1. 初始化磁盘
```bash
parted /dev/sdb
```
执行如下内容
```bash
mklabel gpt
p
mkpart opt 2048s 100%
q
```
3. 配置LVM
```bash
pvcreate /dev/sdb1
vgcreate vnumvg /dev/sdb1
lvcreate -l +100%VG -n vnumlv vnumvg
mkfs.xfs /dev/mapper/vnumvg-vnumlv
```
4. 挂载
```bash
echo "/dev/mapper/vnumvg-vnumlv /var/lib/docker xfs defaults 1 2" >>/etc/fstab
mkdir /var/lib/docker
mount -a
df -h
```
## 分割多块磁盘挂载
> 例如总空间 300G我需要分配成两块 150G 的盘
1. 初始化磁盘
```bash
parted /dev/sdb
```
2. 执行如下内容
```bash
mklabel gpt
p
mkpart primary 0GB 150GB
mkpart primary 150GB 300GB
q
```

View File

@@ -0,0 +1,63 @@
> 本文作者:丁辉
# Parted将两块新硬盘合并成一个
> 我们有两块磁盘 sdb 和 sdc
1. 初始化磁盘
- sdb
```bash
parted /dev/sdb
mklabel gpt
mkpart opt 2048s 100%
q
```
- sdc
```bash
parted /dev/sdc
mklabel gpt
mkpart opt 2048s 100%
q
```
2. 创建 PV
```bash
pvcreate /dev/sdb1
```
```bash
pvcreate /dev/sdc1
```
3. 创建 VG
```bash
vgcreate vg1 /dev/sdb1
```
4. 使用硬盘 sdc1 扩展 VG
```bash
vgextend vg1 /dev/sdc1
```
5. 创建 LV
```bash
lvcreate -l 100%VG -n lv1 vg1
```
> 指定大小 `lvcreate -l00G -n lv1 vg1`
6. 格式化分区
```bash
mkfs -t ext4 /dev/mapper/vg1-lv1
```

View File

@@ -0,0 +1,75 @@
> 本文作者:丁辉
# Parted 磁盘扩容
1. 执行 Parted
```
parted /dev/sdb
```
执行如下内容
```bash
mklabel gpt
mkpart opt 2048s 100%
q
```
2. 创建 PV
```bash
pvcreate /dev/sdb1
```
3. 查看需要扩容磁盘的vg名
```bash
vgdisplay
```
4. 使用硬盘 sdb1 扩展 VG
```bash
vgextend centos /dev/sdb1
```
5. 分配空间
```bash
lvextend -l +100%free /dev/centos/root
```
6. 写入文件系统系统重新识别
```bash
xfs_growfs /dev/mapper/centos-root
```
> `resize2fs /dev/mapper/centos-root` 这个命令似乎不好使呢
## 在原有的盘扩容
1. 执行 Parted
```bash
parted /dev/vda
```
2. 输入
```bash
(parted) resizepart
Partition number? 2
End? [100GB]? 500GB
(parted) q
```
3. 重新获取大小
```bash
resize2fs /dev/vda
```

View File

@@ -0,0 +1,20 @@
> 本文作者:丁辉
# SSH使用密钥连接
1. 调整密钥权限
```bash
chmod 400 *.pem
```
2. SSH 指定密钥连接
```bash
ssh -i ./*.pem root@192.168.1.100 -p 22
```

View File

@@ -0,0 +1,16 @@
> 本文作者:丁辉
# Systemctl查看日志
查看日志
```bash
systemctl status containerd
```
如果查看日志行尾看不到则可以使用 less 协助查看
```bash
systemctl status containerd | less
```

View File

@@ -0,0 +1,37 @@
> 本文作者:丁辉
# Ubuntu允许Root用户登录
1. 配置Root密码
```bash
sudo passwd root
```
2. 修改 ssh 配置
```bash
sudo vi /etc/ssh/sshd_config
```
3. 修改如下参数为 yes
```bash
# 允许 root 登录,但仅限于密钥方式。确保这是 'prohibit-password' 或 'without-password'
PermitRootLogin yes
# 确保公钥认证是开启的
PubkeyAuthentication yes
# 密码认证是关闭的(增加安全性)
# PasswordAuthentication no
```
4. 重启 SSH 服务
```bash
sudo service ssh restart
```

View File

@@ -0,0 +1,10 @@
> 本文作者:丁辉
# Ubuntu关闭用户的交互
配置变量
```bash
export DEBIAN_FRONTEND=noninteractive
```

View File

@@ -0,0 +1,48 @@
> 本文作者:丁辉
# Ubuntu制作Apt离线包
> 拿 vim 举例
## 创建离线包
1. 创建目录
```bash
mkdir /opt/offline-apt-packages
cd /opt/offline-apt-packages
```
2. 将Apt离线包下载到本地
```bash
sudo apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances vim | grep "^\w" | sort -u)
```
## 安装
- 本地安装
```bash
dpkg -i ./*
```
- 通过源安装
```bash
echo "deb file:///opt/offline-apt-packages archives/"| sudo tee /etc/apt/sources.list
```
更新源
```bash
apt-get update
```
安装
```bash
apt install vim
```

View File

@@ -0,0 +1,63 @@
> 本文作者:丁辉
# Ubuntu配置网络
> 不同的 Ubuntu 版本, 可能配置方式不一样
## 配置动态获取IP
1. 编辑网络配置文件
```bash
vi /etc/netplan/00-installer-config.yaml
```
内容如下
```yaml
network:
ethernets:
eth0:
dhcp4: true
```
2. 更新网络配置
```bash
netplan apply
```
## 配置静态IP
1. 编辑网络配置文件
```bash
vi /etc/netplan/00-installer-config.yaml
```
内容如下
```yaml
network:
ethernets:
ens160:
addresses:
- 192.168.100.10/24 #本地IP
nameservers:
addresses:
- 192.168.100.2 #dns配置
- 114.114.114.114
search: []
routes:
- to: default
via: 192.168.100.2 #网关
version: 2
```
2. 更新网络配置
```bash
netplan apply
```

View File

@@ -0,0 +1,55 @@
> 本文作者:丁辉
# Yum打包Rpm文件
> 拿 vim 举例
## 方法一
1. 安装工具
```bash
yum install -y yum-plugin-downloadonly
```
2. 下载
```bash
yum install -y --downloadonly --downloaddir=. vim
```
3. 安装
```bash
rpm -ivh *.rpm --force --nodeps
```
## 方法二
> 只下载保存rpm文件包, 离线环境也可以用
1. 创建目录
```bash
mkdir /root/vim/
```
2. 下载
```bash
yumdownloader --resolve --destdir=/root/vim/ vim
```
> 安装工具
>
> ```bash
> yum install yum-utils -y
> ```
3. 安装
```bash
cd /root/vim/ && rpm -ivh *.rpm --force --nodeps
```

View File

@@ -0,0 +1,30 @@
> 本文作者:丁辉
# 华为服务器设置风扇转速
1. 首先用ssh登录服务器
```bash
ssh root@$IP
```
2. 设置风扇的工作模式为手动并设置手动的时间为1亿秒大概3年多
```bash
ipmcset -d fanmode -v 1 100000000
```
3. 设置风扇转速是百分之多少默认是20%
```bash
ipmcset -d fanlevel -v 20
```
4. 获取风扇的当前模式
```bash
ipmcget -d fanmode
ipmcget -d fanlevel
```

View File

@@ -0,0 +1,40 @@
> 本文作者:丁辉
# 在仅密钥登录的服务器上实现SSH免密登录
> 举例:当前我在腾讯云配置只允许密钥登录服务器,腾讯云下载密钥 private_key(如demo.pem)。
1. 修改密钥权限
```bash
chmod 600 your_private_key
```
2. 确保您的密钥已加载到 ssh-agent
```bash
eval $(ssh-agent)
ssh-add ~/.ssh/your_private_key
```
3. 配置SSH客户端使用该密钥
```bash
vi ~/.ssh/config
```
内容如下
```bash
Host your_server_ip
IdentityFile ~/.ssh/your_private_key
User your_username
```
4. 测试无密码登录
```bash
ssh your_username@your_server_ip
```

96
Docs/安装OpenSSL.md Normal file
View File

@@ -0,0 +1,96 @@
> 本文作者:丁辉
# 安装OpenSSL
## 网络安装
- Centos安装
```bash
yum install openssl openssl-devel -y
```
- Ubuntu安装
```bash
apt install openssl libssl-dev -y
```
## 源码编译安装OpenSSL
[Downloads](https://www.openssl.org/source/) [Old Releases](https://www.openssl.org/source/old/index.html)
1. 依赖安装
- Centos安装
```bash
yum install perl-IPC-Cmd zlib -y
```
- Ubuntu安装
暂未发现所需安装额外依赖
2. 下载源码包
```bash
wget https://www.openssl.org/source/openssl-3.2.1.tar.gz --no-check-certificate
```
3. 解压
```bash
tar -zxvf openssl-*.tar.gz && cd openssl-*
```
4. 配置编译项
```bash
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
```
> 指定静态库:`-fPIC`
5. 开始编译
```bash
make & make install
```
> 同时运行
>
> ```bash
> make -j 4 & make install
> ```
6. 移除旧版本
```bash
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl/ /usr/include/openssl.bak
```
7. 创建软连接
```bash
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/lib/libssl.so.3 /usr/lib64/libssl.so.3
ln -s /usr/local/openssl/lib/libcrypto.so.3 /usr/lib64/libcrypto.so.3
```
8. 添加到动态链接库
```bash
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig
```
9. 验证
```bash
openssl version
```

103
Docs/安装各版本Pip.md Normal file
View File

@@ -0,0 +1,103 @@
> 本文作者:丁辉
# 安装Pip
[Pip安装脚本](https://bootstrap.pypa.io/pip/)
## 脚本安装
1. 下载脚本
```bash
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
```
2. 执行文件
```bash
python get-pip.py
```
## 命令升级
- 使用 Python 升级
```bash
python3 -m pip install --upgrade pip
```
- 使用 Pip 升级
```bash
pip install --upgrade pip
```
## 安装 Pip3
- Centos安装
```bash
yum install python3-pip -y
```
- Ubuntu安装
```bash
apt install python3-pip -y
```
## 安装 Pip2
- Centos安装
```bash
yum install python2-pip -y
```
- Ubuntu安装
1. 启用 universe 源仓库
```bash
add-apt-repository universe
```
2. 安装 Python2
```bash
apt install python2 -y
```
3. 下载安装脚本
```bash
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
```
4. 启用脚本
```bash
python2 get-pip.py
```
5. 验证
```bash
pip2 --version
```
## 安装 Pip
- Centos安装
```bash
yum -y install epel-release
```
```bash
yum install python-pip
```
- Ubuntu安装
俺不知道嘿嘿嘿

View File

@@ -0,0 +1,8 @@
> 本文作者:丁辉
# 查看服务器物理硬件信息
```bash
dmidecode
```

44
Docs/检测CPU负载.md Normal file
View File

@@ -0,0 +1,44 @@
> 本文作者:丁辉
# 检测CPU负载
## 介绍
CPU利用率可以用以下公式计算
CPU利用率(%) = 1 - (闲置时间 / 总时间) x 100
**解释**
- **闲置时间**在指定的时间段内CPU处于闲置状态的时间总和。
- **总时间**这个时间段的总时长通常包括CPU的工作时间和闲置时间。
## 脚本检测
- 使用 Sysstat 工具检测 CPU 负载
1. 安装 Sysstat
- Centos
```bash
yum -y install sysstat
```
- Ubuntu
```bash
apt-get -y install sysstat
```
2. 执行脚本
```bash
curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu-sysstat.sh | bash
```
- 根据 `/proc/stat` 数据计算 CPU 负载
```bash
curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/check-cpu.sh | bash
```

View File

@@ -0,0 +1,45 @@
> 本文作者:丁辉
# 测试Linux网络延迟
## 方法一
> Linux系统下测试网络延迟一般使用Ping命令是最常见的方法。Ping命令以ICMPInternet Control Message Protocol报文形式将封包发送然后等待对端的回复。通过Ping命令可以测试当前网络的基本状况也可以了解当前的网络延迟。
使用的主要的命令格式如下
```bash
ping -c -t
```
\* -c: 指定发送封包的次数
\* -t: 指定发送封包的 TTLTime To Live
以百度Baidu.com为例指定发送50次 TTL设置为5
```bash
ping -c 50 -t 5 www.baidu.com
```
## 方法二
> 除了常规的Ping命令外还可以通过MTRMy Trace Route来检测网络中任意多跳节点间的延迟及包传输情况。MTR将Ping和Traceroute技术进行了结合可以向任意指定的网站发送数据并实时显示传输路径上各跳节点的延迟这样可以很容易发现网络中每一跳节点的状况从而更快的定位网络问题的存在位置。
MTR的主要命令格式如下
```
mtr -r -c
```
\* -r: 以报表形式输出结果
\* -c: 指定发送封包的次数
以百度Baidu.com为例指定发送5次
```
mtr -r -c 5 www.baidu.com
```
MTR会根据发送的封包数显示报表可以从中得到各个节点的延迟、丢包率等信息便于及时的定位网络问题。

View File

@@ -0,0 +1,20 @@
> 本文作者:丁辉
# 测试服务器性能
[Github](https://github.com/masonr/yet-another-bench-script)
1. 克隆代码
```bash
git clone https://github.com/masonr/yet-another-bench-script.git
```
2. 开始测试
```bash
cd yet-another-bench-script
bash yabs.sh
```

View File

@@ -0,0 +1,83 @@
> 本地作者;丁辉
# 测试磁盘是否为SSD
## 方法一
> 判断cat /sys/block/*/queue/rotational的返回值其中*为你的硬盘设备名称例如sda等等如果返回1则表示磁盘可旋转那么就是机械硬盘HDD了反之如果返回0则表示磁盘不可以旋转那么就有可能是固态硬盘SSD了。
```bash
grep ^ /sys/block/*/queue/rotational
```
## 方式二
1. 安装sysbench
```bash
yum install -y sysbench
```
2. 选择要测的磁盘路径 /opt
```bash
cd /opt
```
3. 建文件
> 准备阶段IO测试,线程数为40,创建大小为500M的测试文件64个,共32G,使用了随机读写模式(rndrw)测试300s执行完后会在当前目录下生成一堆小文件。
```bash
sysbench --test=fileio --file-total-size=32G --file-test-mode=rndrw --max-time=300 --max-requests=0 --file-block-size=16K --file-num=64 --num-threads=40 prepare
```
4. 测 IO
```bash
sysbench --test=fileio --file-total-size=32G --file-test-mode=rndrw --max-time=300 --max-requests=0 --file-block-size=16K --file-num=64 --num-threads=40 run
```
5. 输出结果
```bash
WARNING: the --test option is deprecated. You can pass a script name or path on the command line without any options.
WARNING: --num-threads is deprecated, use --threads instead
WARNING: --max-time is deprecated, use --time insteadsysbench 1.0.17 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 40
Initializing random number generator from current time
Extra file open flags: (none)64 files, 512MiB each32GiB total file sizeBlock size 16KiBNumber of IO requests: 0Read/Write ratio for combined random IO test: 1.50Periodic FSYNC enabled, calling fsync() each 100 requests.Calling fsync() at the end of test, Enabled.Using synchronous I/O modeDoing random r/w testInitializing worker threads...
Threads started!
File operations:
reads/s: 36369.44
writes/s: 24246.29
fsyncs/s: 38802.60
Throughput:
read, MiB/s: 568.27
written, MiB/s: 378.85
General statistics:
total time: 300.0042s
total number of events: 29824059
Latency (ms):
min: 0.00
avg: 0.37
max: 8.21
95th percentile: 1.96
sum: 11174442.44
Threads fairness:
events (avg/stddev): 745601.4750/1916.86
execution time (avg/stddev): 279.3611/0.06
```
6. 解读
读写次数在2万~4万间吞吐量在300~600M/s可以判定磁盘为SSD。

88
Docs/源码升级Gcc.md Normal file
View File

@@ -0,0 +1,88 @@
> 本文作者:丁辉
# 源码升级Gcc
[Gcc源码文件下载](https://ftp.gnu.org/gnu/gcc/)
1. 下载源码包
```bash
wget https://ftp.gnu.org/gnu/gcc/gcc-13.2.0/gcc-13.2.0.tar.gz
```
2. 解压源码包
```bash
tar -zxvf gcc-*.tar.gz && cd gcc-*
```
3. 配置编译项
```bash
./configure --prefix=/usr/local/gcc-13.2.0 --enable-checking=release --enable-languages=c,c++ --disable-multilib
```
> 遇到报错configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
>
> 解决方案gcc 目录下执行如下命令即可解决
>
> ```bash
> ./contrib/download_prerequisites
> ```
**构建参数**
| 参数 | 含义 |
| :-----------------------: | :---------------------------------------------------------: |
| ./configure | 源代码安装软件时用于配置软件包 |
| --enable-checking=release | 启用编译器的检查功能,但仅限于 release 模式 |
| --enable-languages=c,c++ | 指定 GCC 将支持 C 和 C++ 编程语言 |
| --disable-multilib | 禁用 GCC 的多架构支持,使其只会生成与主系统架构相匹配的代码 |
4. 开始编译
```bash
make
```
> 同时运行
>
> ```bash
> make -j 4
> ```
5. 编译安装
```bash
make install
```
6. 替换旧版本, 移除旧版本
```bash
mv /usr/bin/gcc /usr/bin/gcc.bak
mv /usr/bin/g++ /usr/bin/g++.bak
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
```
7. 制作软连接
```bash
ln -s /usr/local/gcc-13.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-13.2.0/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-13.2.0/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6
```
8. 查看动态库
```bash
strings /usr/lib64/libstdc++.so.6 | grep CXXABI
```
9. 验证版本
```bash
gcc --version
```

View File

@@ -0,0 +1,73 @@
> 本文作者:丁辉
# 系统安全策略配置
## 限制 Linux 最大限制远程登录次数
### 方法一
1. 编辑 SSH 服务配置文件
```bash
vi /etc/ssh/sshd_config
```
修改如下内容
```bash
# 设置每个IP地址的最大登录尝试次数
MaxAuthTries 3
# 设置封锁的时间单位为秒这里设置为300秒即5分钟
LoginGraceTime 300
```
2. 重载配置
```bash
systemctl reload sshd
```
### 方法二
1. 安装 fail2ban
```bash
yum install epel-release -y
yum install fail2ban -y
```
2. 配置 fail2ban
```bash
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
```
编辑`jail.local`文件,找到并更改以下参数
```bash
# 设置ban的时间以秒为单位默认值为600秒即10分钟
bantime = 600
# 允许尝试登录的最大次数
maxretry = 5
# 将这个值设置为yesfail2ban将禁止任何主机的IP如果该主机的IP多次失败这对于保护你的系统非常有用。
# 但要谨慎使用,以防止合法用户因错误登录被阻止。
banaction = iptables-multiport
```
3. 启动 fail2ban 服务
```bash
systemctl start fail2ban
systemctl enable fail2ban
```
4. 检查fail2ban状态
```bash
fail2ban-client status
```

43
Docs/配置Pip加速.md Normal file
View File

@@ -0,0 +1,43 @@
> 本文作者:丁辉
# 配置Pip加速
- 临时方式
```bash
pip install $all -i https://pypi.tuna.tsinghua.edu.cn/simple/
```
- 永久方式
```bash
vi /etc/pip.conf
```
```bash
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com
```
**镜像站点**
- 豆瓣
```bash
https://pypi.douban.com/simple
```
- 阿里云
```bash
https://mirrors.aliyun.com/pypi/simple
```
- 清华大学
```bash
https://pypi.tuna.tsinghua.edu.cn/simple
```

153
File/Conf/openssl.cnf Normal file
View File

@@ -0,0 +1,153 @@
####################################################################
[ ca ]
default_ca = CA_default # The default ca section
####################################################################
[ CA_default ]
dir = /etc/pki/CA # Where everything is kept
certs = $dir/certs # Where the issued certs are kept
crl_dir = $dir/crl # Where the issued crl are kept
database = $dir/index.txt # database index file.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crlnumber = $dir/crlnumber # the current crl number
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/cakey.pem# The private key
RANDFILE = $dir/private/.rand # private random number file
x509_extensions = usr_cert # The extentions to add to the cert
# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options
# Extension copying option: use with caution.
# copy_extensions = copy
# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions = crl_ext
default_days = 365 # how long to certify for
default_crl_days= 30 # how long before next CRL
default_md = sha256 # use SHA-256 by default
preserve = no # keep passed DN ordering
# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy = policy_match
# For the CA policy
[ policy_match ]
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
# For the 'anything' policy
# At this point in time, you must list all acceptable 'object'
# types.
[ req ]
default_bits = 2048
default_md = sha256
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca # The extentions to add to the self signed cert
# Passwords for private keys if not present they will be prompted for
# input_password = secret
# output_password = secret
# This sets a mask for permitted string types. There are several options.
# default: PrintableString, T61String, BMPString.
# pkix : PrintableString, BMPString (PKIX recommendation before 2004)
# utf8only: only UTF8Strings (PKIX recommendation after 2004).
# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
# MASK:XXXX a literal mask value.
# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
string_mask = utf8only
# req_extensions = v3_req # The extensions to add to a certificate request
[ req_distinguished_name ]
countryName = Country Name (2 letter code)
countryName_default = XX
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
#stateOrProvinceName_default = Default Province
localityName = Locality Name (eg, city)
localityName_default = Default City
0.organizationName = Organization Name (eg, company)
0.organizationName_default = Default Company Ltd
# we can do this but it is not needed normally :-)
#1.organizationName = Second Organization Name (eg, company)
#1.organizationName_default = World Wide Web Pty Ltd
organizationalUnitName = Organizational Unit Name (eg, section)
#organizationalUnitName_default =
commonName = Common Name (eg, your name or your server\'s hostname)
commonName_max = 64
emailAddress = Email Address
emailAddress_max = 64
# SET-ex3 = SET extension number 3
[ v3_req ]
# Extensions to add to a certificate request
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
[ v3_ca ]
# Extensions for a typical CA
# PKIX recommendation.
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer
# This is what PKIX recommends but some broken software chokes on critical
# extensions.
#basicConstraints = critical,CA:true
# So we do this instead.
basicConstraints = CA:true
# Key usage: this is typical for a CA certificate. However since it will
# prevent it being used as an test self-signed certificate it is best
# left out by default.
# keyUsage = cRLSign, keyCertSign
# Some might want this also
# nsCertType = sslCA, emailCA
# Include email address in subject alt name: another PKIX recommendation
# subjectAltName=email:copy
# Copy issuer details
# issuerAltName=issuer:copy
# DER hex encoding of an extension: beware experts only!
# obj=DER:02:03
# Where 'obj' is a standard or added object
# You can even override a supported extension:
# basicConstraints= critical, DER:30:03:01:01:FF

19
File/Conf/rsyncd.conf Normal file
View File

@@ -0,0 +1,19 @@
uid = root
gid = root
port = 873
use chroot = no
max connections = 36000
log file=/var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
timeout = 600
[data]
comment = none # 各节点看自己情况修改描述
path = /data
read only = no
ignore errors = yes
auth users = rsync
secrets file = /etc/rsync_salve.pass
hosts allow = none # 直接写IP地址 192.168.1.10 或者网段 192.168.1.10/24
hosts deny = *

View File

@@ -0,0 +1,14 @@
# 作者: 丁辉
[Unit]
Description=Inotify Service
After=network.target
[Service]
RemainAfterExit=yes
ExecStart=/opt/rsync_inotify.sh
ExecStop=pkill -f "rsync_inotify.sh"
ExecReload=/opt/rsync_inotify.sh && pkill -f "rsync_inotify.sh"
Restart=on-abnormal
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,14 @@
# 作者: 丁辉
[Unit]
Description=Sersync2 Service
After=network.target
[Service]
RemainAfterExit=yes
ExecStart=/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
ExecStop=/usr/bin/pkill sersync2
ExecReload=/usr/bin/pkill sersync2 && /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
Restart=on-abnormal
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,107 @@
#!/bin/bash
#############################################################################################
# 用途: 本脚本用于大包内核离线升级包
# 作者: 丁辉
# 编写时间: 2023-12-03
# 更新时间: 2024-05-20
#############################################################################################
# 加载检测脚本
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
# Centos内核文件: https://elrepo.org/linux/kernel/
# Ubuntu内核文件: https://kernel.ubuntu.com/mainline/ 国内: https://mirrors.edge.kernel.org/pub/linux/kernel/
# 存放Cenots8内核RPM文件包数组
Centos8_RPM=(
"https://elrepo.org/linux/kernel/el8/x86_64/RPMS/kernel-lt-5.4.262-1.el8.elrepo.x86_64.rpm"
"https://elrepo.org/linux/kernel/el8/x86_64/RPMS/kernel-lt-modules-5.4.262-1.el8.elrepo.x86_64.rpm"
"https://elrepo.org/linux/kernel/el8/x86_64/RPMS/kernel-lt-core-5.4.262-1.el8.elrepo.x86_64.rpm"
)
Centos7_RPM=(
"https://elrepo.org/linux/kernel/el7/x86_64/RPMS/kernel-lt-5.4.262-1.el7.elrepo.x86_64.rpm"
)
function CURL_UBUNTU_DEB(){
CHECK_CPU
SEND_INFO "正在下载内核DEB文件包,请稍后"
VERSION=$(curl -s https://kernel.ubuntu.com/mainline/ | awk -F 'href="' '{print $2}' | awk -F '/"' '{print $1}' | sort -V | grep -v rc | grep -v Name | tail -n 1)
FILES=$(curl -s https://kernel.ubuntu.com/mainline/v6.6.4/amd64/ | grep deb | awk -F 'href="' '{print $2}' | awk -F '.deb' '{print $1".deb"}' | grep -v linux-headers)
URL="https://kernel.ubuntu.com/mainline/$VERSION/$ARCH_TYPE_2"
for i in ${FILES[@]}
do
curl -sO $URL/$i
done
VERSION="Ubuntu"
SEND_INFO "开始打包: $VERSION 离线内核升级包"
CHECK_COMMAND_ECHO rm -rf linux-headers-*
curl -sO https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh
sed -i.bak 's/source <(curl -sS https:\/\/gitee.com\/offends\/Linux\/raw\/main\/File\/Shell\/Check_command.sh)/source .\/Check_command.sh/g' Core.sh
CHECK_COMMAND_ECHO tar -zcvf $VERSION\_Core.tar.gz *.deb Check_command.sh Core.sh
SEND_INFO "正在清理临时文件"
CHECK_COMMAND_ECHO rm -rf *.deb && mv Core.sh.bak Core.sh
}
function CHECK_CENTOS_FILE(){
SEND_INFO "开始打包: $VERSION 离线内核升级包"
curl -sO https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh
sed -i.bak 's/source <(curl -sS https:\/\/gitee.com\/offends\/Linux\/raw\/main\/File\/Shell\/Check_command.sh)/source .\/Check_command.sh/g' Core.sh
CHECK_COMMAND_ECHO tar -zcvf $VERSION\_Core.tar.gz *.rpm Check_command.sh Core.sh
SEND_INFO "正在清理临时文件"
CHECK_COMMAND_ECHO rm -rf *.rpm && mv Core.sh.bak Core.sh
}
# 判断用户传入的参数为哪个系统
function CHECK_USER_READ(){
case $1 in
Centos7)
SEND_INFO "正在下载内核RPM文件包,请稍后"
for i in ${Centos7_RPM[@]}
do
curl -sO $i
VERSION="CentOS7"
done
CHECK_CENTOS_FILE
;;
Centos8)
SEND_INFO "正在下载内核RPM文件包,请稍后"
for i in ${Centos8_RPM[@]}
do
curl -sO $i
VERSION="CentOS8"
done
CHECK_CENTOS_FILE
;;
Ubuntu)
CURL_UBUNTU_DEB
;;
--help | -h)
echo "Usage: script_name [OPTIONS] [ARGUMENTS]"
echo ""
echo "Description:"
echo " Offends"
echo ""
echo "Options:"
echo " -h, --help 显示此帮助信息"
echo " Centos7 打包Centos7内核离线包"
echo " Centos8 打包Centos8内核离线包"
echo " Ubuntu 打包Centos8内核离线包"
echo ""
echo "Examples:"
echo " 示例 1: ./Build_Core_Tar.sh Centos7"
exit 0
;;
*)
SEND_ERROR "参数错误,请使用 --help,-h 查看支持版本"
;;
esac
}
function ALL(){
CHECK_NETWORK
CHECK_USER_READ $@
}
ALL $@

284
File/Shell/Check_command.sh Normal file
View File

@@ -0,0 +1,284 @@
#!/bin/bash
#############################################################################################
# 用途: 提供一些常用的函数,拱其他脚本调用
# 作者: 丁辉
# 编写时间: 2023-11-27
#############################################################################################
# 加载检测脚本
# source <(curl -sS https://gitee.com/offends/Shell/raw/main/Check_command.sh)
# 定义颜色
RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[32m'
YELLOW='\033[33m'
# 定义时间格式
TIME="+%Y-%m-%d %H:%M:%S"
# 定义函数 send_info
function SEND_INFO() {
info=$1
echo -e "${GREEN}$(date "$TIME") INFO: $info${NC}"
}
# 定义函数 send_warn
function SEND_WARN() {
warn=$1
echo -e "${YELLOW}$(date "$TIME") WARN: $warn${NC}"
}
# 定义函数 send_error
function SEND_ERROR() {
error=$1
echo -e "${RED}$(date "$TIME") ERROR: $error${NC}"
}
# print输出绿色字体
function GREEN_PRINTF() {
info=$1
printf "${GREEN}$(date "$TIME") INFO: $info${NC}\n"
}
# 打印系统信息
function FUNC_PRINT_SYSTEM_INFO() {
# 获取系统信息
CENTOS_VERSION=$(cat /etc/os-release | grep PRETTY_NAME= | awk -F '"' '{print $2}')
KERNEL_VERSION=$(uname -a | awk '{print $3}')
CPU_MODEl=$(cat /proc/cpuinfo | grep 'model name' | head -1 | awk -F ':' '{print $2}' | sed 's#^[ \t]*##g')
CPU_CORE=$(grep -c "processor" /proc/cpuinfo)
MEMORY_SIZE=$(free -h | awk '/Mem/ {print $2}')
# 打印系统信息
SEND_INFO "欢迎使用阿辉的脚本"
SEND_INFO "当前系统信息如下: "
SEND_INFO "=========================================================="
SEND_INFO "服务器架构: $(arch)"
SEND_INFO "系统版本: ${CENTOS_VERSION}"
SEND_INFO "内核版本: ${KERNEL_VERSION}"
SEND_INFO "内存大小: ${MEMORY_SIZE}"
SEND_INFO "处理器核数: ${CPU_CORE}"
SEND_INFO "处理器型号: ${CPU_MODEl}"
SEND_INFO "=========================================================="
}
# 检查服务器系统版本
function CHECK_OS() {
FWQ_NAME=$(cat /etc/os-release | grep '^NAME' | awk -F '"' '{print $2}')
if [[ $FWQ_NAME == "CentOS Linux" ]] || [[ $FWQ_NAME == "CentOS Stream" ]];then
OS=centos
OS_VERSION=$(cat /etc/os-release | grep -oP 'VERSION_ID="\K[^"]+' | cut -d '.' -f 1)
elif [[ $FWQ_NAME == "Debian GNU/Linux" ]];then
OS=debian
OS_VERSION=$(cat /etc/issue | awk -F ' ' '{print $3}')
elif [[ $FWQ_NAME == "Ubuntu" ]];then
OS=ubuntu
OS_VERSION=$(cat /etc/os-release | grep VERSION_ID= | grep -oE '[0-9]+\.[0-9]+' | cut -d'.' -f1)
else
SEND_ERROR "无法识别的系统版本"
exit 1
fi
}
# 判断服务器架构
function CHECK_CPU() {
if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then
ARCH_TYPE_1=x86_64
ARCH_TYPE_2=amd64
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then
ARCH_TYPE_1=aarch64
ARCH_TYPE_2=arm64
elif [ $(arch) = "i386" ]; then
ARCH_TYPE=x86_64
ARCH_TYPE_2=amd64
else
SEND_ERROR "无法识别的系统架构: $(arch)"
exit 1
fi
}
# 启动内核更新脚本
function CHECK_CORE(){
# 询问是否需要升级内核
read -p "是否需要升级内核 [Y/n]" is_core
case $is_core in
[yY][eE][sS]|[yY])
curl -sLO https://gitee.com/offends/Offends/raw/main/Shell/Core.sh
chmod +x Core.sh
./Core.sh $@
;;
[nN][oO]|[nN])
SEND_INFO "跳过内核更新"
;;
"")
SEND_ERROR "值不能为空,请重新输入"
;;
*)
SEND_ERROR "输入错误,请重新输入"
CHECK_CORE
;;
esac
}
# 检查服务器网络连接
function CHECK_NETWORK() {
SEND_INFO "正在检查网络连接"
PING=$(ping -c 3 www.baidu.com | grep 'icmp_seq' | wc -l)
if [[ ${PING} -eq 0 ]];then
SEND_ERROR "网络连接失败,请检查网络连接"
exit 1
fi
}
# 检测文件是否存在
function CHECK_FILE(){
if [ ! -f "$@" ]; then
SEND_ERROR "$@ 文件不存在"
exit 1
fi
}
# 检测文件是否存在(多文件情况)
function CHECK_FILES(){
shopt -s nullglob
for file in "$@"; do
if [ ! -f "$file" ]; then
SEND_ERROR "$file 文件不存在"
exit 1
fi
done
}
# 检测目录是否存在,不存在则创建
function CHECK_DIR(){
if [ ! -d "$@" ]; then
mkdir -p "$@" > /dev/null 2>&1 || true
fi
}
# 检测固定位置的二进制文件是否存在
function CHECK_BIN(){
if [ ! -f "$@" ]; then
INSTALL_BIN=false
fi
}
# 检测命令是否执行正确,正确则输出$1,错误则输出$2并退出脚本
function CHECK_COMMAND_TRUE() {
if [ $? -eq 0 ]; then
SEND_INFO "$1"
else
SEND_ERROR "$2"
exit 1
fi
}
# 判断用户是否存在,不存在则创建
function CHECK_USER(){
if ! id -u "$@" >/dev/null 2>&1; then
useradd -m -s /bin/bash --no-user-group "$@" > /dev/null 2>&1 || true
fi
}
# 判断用户组是否存在,不存在则创建
function CHECK_GROUP(){
if ! grep -q "$@" /etc/group; then
groupadd "$@" > /dev/null 2>&1 || true
fi
}
# 用户加入组
function ADD_USER_GROUP(){
CHECK_USER "$1"
CHECK_GROUP "$2"
if ! id -nG "$1" | grep -qw "$2"; then
SEND_INFO "正在将用户 $1 加入用户组 $2"
usermod -aG "$2" "$1" > /dev/null 2>&1 || true
fi
id "$1" || true
}
# 定义输出为空,并且失败不会退出脚本
function NULL_TRUE(){
eval "$*" > /dev/null 2>&1 || true
}
# 失败不会退出脚本,输出命令执行结果
function NULL_TRUE_ECHO(){
eval "$*" || true
}
# 检测命令是否执行成功,不输出命令执行结果
function CHECK_COMMAND_NULL() {
# 执行传入的命令
eval "$*" > /dev/null 2>&1
# 检查命令执行状态
if [ $? -ne 0 ]; then
SEND_ERROR "执行失败, 退出脚本, 请检查命令是否正确: $*"
exit 1
fi
}
# 检测命令是否执行成功,输出命令执行结果
function CHECK_COMMAND_ECHO() {
# 执行传入的命令
eval "$*"
# 检查命令执行状态
if [ $? -ne 0 ]; then
SEND_ERROR "执行失败, 退出脚本, 请检查命令是否正确: $*"
exit 1
fi
}
# 网络安装软件
function CHECK_INSTALL() {
# 接收传递给脚本的参数列表
packages=("$@")
log_file="/tmp/check_install_log" # 定义日志文件路径
for pkg in "${packages[@]}"; do
if command -v yum >/dev/null 2>&1; then
SEND_INFO "正在安装 $pkg,请稍后"
yum install -y "$pkg" >>"$log_file" 2>&1
if [ $? -ne 0 ]; then
SEND_ERROR "安装 $pkg 失败,请查看日志"
tail -n 10 "$log_file" # 输出最后10行日志
rm -rf $log_file
exit 1
fi
elif command -v apt >/dev/null 2>&1; then
SEND_INFO "正在安装 $pkg,请稍后"
apt-get install -y "$pkg" >>"$log_file" 2>&1
if [ $? -ne 0 ]; then
SEND_ERROR "安装 $pkg 失败,请查看日志"
tail -n 10 "$log_file" # 输出最后10行日志
rm -rf $log_file
exit 1
fi
else
SEND_ERROR "无法识别的系统软件包管理工具"
exit 1
fi
done
}
# 检测某个systemd服务是否存在
function CHECK_SYSTEMD(){
if ! command -v $@ >/dev/null 2>&1; then
SEND_ERROR "错误,请检查 $@ 是否安装"
exit 1
else
SEND_INFO "$@ 服务已安装"
if ! systemctl status $@ >/dev/null 2>&1; then
SEND_WARN "$@ 服务未启动,正在启动 $@ 服务"
if ! systemctl start $@ >/dev/null 2>&1; then
SEND_ERROR "$@ 服务启动失败,请检查 $@ 服务"
exit 1
fi
fi
fi
}

27
File/Shell/Clean_git.sh Normal file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
#############################################################################################
# 用途: 清理 Git 提交记录
# 作者: 丁辉
# 编写时间: 2024-01-03
# 使用方法
# curl -sfL https://gitee.com/offends/Linux/raw/main/File/Shell/Clean_git.sh | bash
#############################################################################################
# 定义变量
# 你的分支名称
BRANCH="main"
# 创建了一个新的分支
git checkout --orphan latest_branch
# 添加所有文件
git add -A
# 提交更改
git commit -am "synchronization"
# 删除分支
git branch -D $BRANCH
# 将当前分支重命名
git branch -m $BRANCH
# 最后,强制更新存储库
git push -f origin $BRANCH

381
File/Shell/Core.sh Normal file
View File

@@ -0,0 +1,381 @@
#!/bin/bash
#############################################################################################
# 用途: 内核版本升级
# 作者: 丁辉
# 编写时间: 2023-12-02
# 本脚本支持: Centos7/Centos8/Debian10/Debian11/Debian12/Ubuntu* 内核升级
#############################################################################################
# 检查服务器网络连接
function CHECK_NETWORK() {
PING=$(ping -c 3 www.baidu.com | grep 'icmp_seq' | wc -l)
if [[ ${PING} -eq 0 ]];then
SEND_ERROR "未检测到网络,跳过网络安装系统基础依赖"
else
CHECK_INSTALL curl
fi
}
function CHECK_INSTALL() {
# 接收传递给脚本的参数列表
packages=("$@")
log_file="/tmp/check_install_log" # 定义日志文件路径
for pkg in "${packages[@]}"; do
if command -v yum >/dev/null 2>&1; then
echo -e "\033[32m正在安装 $pkg,请稍后\033[0m"
yum install -y "$pkg" >>"$log_file" 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31m安装 $pkg 失败,请查看日志\033[0m"
tail -n 10 "$log_file" # 输出最后10行日志
rm -rf $log_file
exit 1
fi
elif command -v apt >/dev/null 2>&1; then
echo -e "\033[32m正在安装 $pkg,请稍后\033[0m"
apt-get install -y "$pkg" >>"$log_file" 2>&1
if [ $? -ne 0 ]; then
echo -e "\033[31m安装 $pkg 失败,请查看日志\033[0m"
tail -n 10 "$log_file" # 输出最后10行日志
rm -rf $log_file
exit 1
fi
else
echo -e "\033[31m无法识别的系统软件包管理工具\033[0m"
exit 1
fi
done
}
# 检测服务器架构
function IF_CHECK_CORE_ALL(){
if [ $(arch) = "x86_64" ] || [ $(arch) = "amd64" ]; then
ARCH_TYPE=amd64
elif [ $(arch) = "aarch64" ] || [ $(arch) = "arm64" ]; then
ARCH_TYPE=arm64
SEND_ERROR "本脚本暂不支持 $(arch) 架构,或许你可以删除本段判断试试哈哈"
exit 1
else
SEND_ERROR "无法识别的系统架构: $(arch)"
exit 1
fi
IF_CHECK_OS
}
function IF_OS_ENV(){
# 判断 OS_TRUE=0,则退出脚本
if [ ${OS_TRUE} -eq 0 ]; then
SEND_ERROR "本脚本暂不支持 ${OS} ${OS_VERSION} 系统"
exit 1
fi
}
# 检测服务器系统及版本
function IF_CHECK_OS(){
CHECK_OS
OS_TRUE=1
if [ "$OS" = "centos" ]; then
if [ "$OS_VERSION" -ne 7 ] && [ "$OS_VERSION" -ne 8 ]; then
OS_TRUE=0
fi
IF_OS_ENV
IF_CHECK_CORE
elif [ "$OS" = "debian" ]; then
IF_CHECK_CORE
elif [ "$OS" = "ubuntu" ]; then
IF_CHECK_CORE
else
SEND_ERROR "无法识别的系统版本"
exit 1
fi
}
# 检测内核版本
function IF_CHECK_CORE(){
CHECK_OS
if [ ${OS} = "centos" ]; then
# 判断内核是否低于5,如果低于5则更新内核
if [ $(uname -r | awk -F '.' '{print $1}') -lt 5 ]; then
IF_UPDATE_ONLINE
else
SEND_INFO "当前内核版本为 $(uname -r),无需更新"
fi
elif [ ${OS} = "ubuntu" ]; then
if [ $(uname -r | awk -F '.' '{print $1}') -lt 6 ]; then
IF_UPDATE_ONLINE
else
SEND_INFO "当前内核版本为 $(uname -r),无需更新"
fi
elif [ ${OS} = "debian" ]; then
if [ ${OS_VERSION} -eq 10 ] || [ ${OS_VERSION} -eq 11 ]; then
if [ $(uname -r | awk -F '.' '{print $1}') -lt 5 ]; then
IF_UPDATE_ONLINE
else
SEND_INFO "当前内核版本为 $(uname -r),无需更新"
fi
elif [ ${OS_VERSION} -eq 12 ]; then
if [ $(uname -r | awk -F '.' '{print $1}') -lt 6 ]; then
IF_UPDATE_ONLINE
else
SEND_INFO "当前内核版本为 $(uname -r),无需更新"
fi
else
SEND_ERROR "当前 Debian 系统 $(uname -r) 版本暂时不支持内核更新"
exit 1
fi
else
SEND_ERROR "当前系统暂时不支持内核更新"
exit 1
fi
}
# 判断在线或离线升级
function IF_UPDATE_ONLINE(){
while true; do
read -p "本脚本支持 在线(o)/离线(l) 升级内核,请选择升级方式 [o(默认)/l]: " UPDATE_TYPE
case $UPDATE_TYPE in
o|"")
UPDATE_TYPE=online
SEND_INFO "您选择的升级方式为: ${UPDATE_TYPE} 在线升级"
break
;;
l)
UPDATE_TYPE=local
SEND_INFO "您选择的升级方式为: ${UPDATE_TYPE} 离线升级"
break
;;
*)
SEND_ERROR "输入错误,请重新输入"
;;
esac
done
IF_UPDATE_TYPE
}
# 判断升级方式
function IF_UPDATE_TYPE(){
if [ ${UPDATE_TYPE} = "online" ]; then
if [ ${OS} = "centos" ]; then
if [ ${OS_VERSION} -eq 7 ]; then
UPDATE_CENTOS_ONLINE_7
elif [ ${OS_VERSION} -eq 8 ]; then
UPDATE_CENTOS_ONLINE_8
fi
elif [ ${OS} = "debian" ]; then
UPDATE_DEBIAN_ONLINE
elif [ ${OS} = "ubuntu" ]; then
UPDATE_UBUNTU_ONLINE
fi
elif [ ${UPDATE_TYPE} = "local" ]; then
if [ ${OS} = "centos" ]; then
if [ ${OS_VERSION} -eq 7 ]; then
UPDATE_CENTOS_LOCAL_7
elif [ ${OS_VERSION} -eq 8 ]; then
UPDATE_CENTOS_LOCAL_8
fi
elif [ ${OS} = "debian" ]; then
UPDATE_DEBIAN_LOCAL
elif [ ${OS} = "ubuntu" ]; then
UPDATE_UBUNTU_LOCAL
fi
fi
}
#选择内核版本
function SELECT_CORE(){
# 安装内核
# 查看可提供升级的版本
SEND_INFO "正在查询当前内核可升级版本"
CHECK_COMMAND_ECHO yum list available --disablerepo='*' --enablerepo=elrepo-kernel | grep -v Loaded | grep -v Loading | grep -v "*" | grep -v Available
# 让用户通过输入选择版本
if [ ${ALL_DEFAULT_YES} = true ]; then
KERNEL_VERSION=kernel-lt
SEND_INFO "您选择的内核版本为: ${KERNEL_VERSION}"
else
while true; do
read -p "请输入您想要升级的内核版本[lt(默认)/ml]: " KERNEL_VERSION
case $KERNEL_VERSION in
lt|"")
KERNEL_VERSION=kernel-lt
SEND_INFO "您选择的内核版本为: ${KERNEL_VERSION}"
break
;;
ml)
KERNEL_VERSION=kernel-ml
SEND_INFO "您选择的内核版本为: ${KERNEL_VERSION}"
break
;;
*)
SEND_ERROR "输入错误,请重新输入"
;;
esac
done
fi
}
# 配置内核启动顺序
function CORE_SEQUENCE(){
# 配置系统默认启动内核
if [ ${ALL_DEFAULT_YES} = true ]; then
DEFAULT_KERNEL=0
else
while true; do
SEND_INFO "正在获取内核版本序号"
awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
read -p "请选择系终启动默认内核序号(默认0): " DEFAULT_KERNEL
if [ -z ${DEFAULT_KERNEL} ]; then
DEFAULT_KERNEL=0
break
elif [ ${DEFAULT_KERNEL} -ge 0 ] && [ ${DEFAULT_KERNEL} -le 9 ]; then
break
else
SEND_ERROR "输入错误,请重新输入"
fi
done
fi
# 设置开机启动
SEND_INFO "正在设置开机启动,请稍后"
grub2-set-default ${DEFAULT_KERNEL}
REBOOT
}
function REBOOT(){
if [ ${ALL_DEFAULT_YES} = true ]; then
SEND_INFO "正在重启系统,请稍后"
reboot
else
while true; do
read -p "是否重启系统[y(默认)/n]: " REBOOT
case $REBOOT in
y|"")
SEND_INFO "正在重启系统,请稍后"
reboot
break
;;
n)
SEND_INFO "请手动重启系统"
break
;;
*)
SEND_ERROR "输入错误,请重新输入"
;;
esac
done
fi
}
# 升级 CentOS 内核
function UPDATE_CENTOS_ONLINE_7(){
SEND_INFO "正在加载 Kernel 源,请稍后"
# 载入公钥
CHECK_COMMAND_NULL rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装 ELRepo 源
NULL_TRUE rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
SELECT_CORE
# 安装内核
SEND_INFO "正在安装内核,请稍后"
CHECK_COMMAND_ECHO yum --enablerepo=elrepo-kernel install ${KERNEL_VERSION} -y
CORE_SEQUENCE
}
function UPDATE_CENTOS_LOCAL_7(){
CHECK_FILES kernel-*.rpm
SEND_INFO "正在安装本地内核包,请稍后"
CHECK_COMMAND_ECHO yum localinstall -y kernel-*.rpm
CORE_SEQUENCE
}
function UPDATE_CENTOS_ONLINE_8(){
SEND_INFO "正在加载 Kernel 源,请稍后"
# 载入公钥
CHECK_COMMAND_NULL rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装 ELRepo 源
NULL_TRUE rpm -Uvh https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm
SELECT_CORE
# 安装内核
SEND_INFO "正在安装内核,请稍后"
CHECK_COMMAND_ECHO yum --enablerepo=elrepo-kernel install ${KERNEL_VERSION} -y
CORE_SEQUENCE
}
function UPDATE_CENTOS_LOCAL_8(){
UPDATE_CENTOS_LOCAL_7
}
function UPDATE_UBUNTU_ONLINE(){
SEND_INFO "正在获取内核版本,请稍后"
VERSION=$(./ubuntu-mainline-kernel.sh -c | grep A | grep -o 'v[0-9]\+\(\.[0-9]\+\)\{2\}')
SEND_INFO "最新稳定版本为: ${VERSION}"
SEND_INFO "正在安装内核,请稍后"
curl -sS https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh | bash -s -- -i ${VERSION}
CHECK_COMMAND_TRUE "安装成功" "安装失败请查看日志"
REBOOT
# # 第二种更新方式
# sudo apt update
# apt search linux-image
# apt-get upgrade linux-image-generic
}
function UPDATE_UBUNTU_LOCAL(){
CHECK_FILES *.deb
SEND_INFO "正在安装本地内核包,请稍后"
CHECK_COMMAND_ECHO dpkg --install *.deb
REBOOT
}
function UPDATE_DEBIAN_ONLINE(){
# apt search linux-image
CHECK_COMMAND_ECHO echo "deb http://deb.debian.org/debian buster-backports main" > /etc/apt/sources.list.d/backports.list
CHECK_COMMAND_ECHO apt update
CHECK_COMMAND_ECHO apt -t buster-backports install linux-image-amd64 -y
CHECK_COMMAND_TRUE "linux-image 安装成功" "安装失败请查看日志"
CHECK_COMMAND_ECHO apt -t buster-backports install linux-headers-amd64 -y
CHECK_COMMAND_TRUE "linux-headers 安装成功" "安装失败请查看日志"
SEND_INFO "正在更新开机启动顺序,请稍后"
CHECK_COMMAND_TRUE update-grub
REBOOT
}
function UPDATE_DEBIAN_LOCAL(){
SEND_ERROR "暂不支持 Debian 离线升级内核,有需求就提个 issue 吧"
}
function ALL(){
CHECK_NETWORK
# 加载检测脚本
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
CHECK_PARAMETER $@
FUNC_PRINT_SYSTEM_INFO
IF_CHECK_CORE_ALL
}
# 检测外部是否传入参数
function CHECK_PARAMETER(){
if [ "$#" -eq 0 ] || [ "$#" -eq 1 ]; then
case $1 in
ALL_DEFAULT_YES=1)
ALL_DEFAULT_YES=true
;;
*)
if [ "$#" -eq 1 ]; then
SEND_ERROR "输入参数错误,请查看帮助文档: https://gitee.com/offends/Linux/blob/main/%E8%84%9A%E6%9C%AC/README.md"
exit 1
fi
ALL_DEFAULT_YES=false
;;
esac
else
SEND_ERROR "输入参数错误,请查看帮助文档: https://gitee.com/offends/Linux/blob/main/%E8%84%9A%E6%9C%AC/README.md"
exit 1
fi
}
ALL $@

74
File/Shell/button.sh Normal file
View File

@@ -0,0 +1,74 @@
#!/bin/bash
#############################################################################################
# 用途: Shell模拟按钮
# 作者: 丁辉
# 编写时间: 2024-05-20
#############################################################################################
function Button() {
# 定义选项列表
options=("选项一" "选项二")
# 初始化选项索引
selected_index=0
# 清除屏幕
clear
# 显示选项列表
display_options() {
for i in "${!options[@]}"; do
if [ $i -eq $selected_index ]; then
echo "> ${options[i]}"
else
echo " ${options[i]}"
fi
done
}
# 循环直到用户选择退出
while true; do
display_options
# 读取用户输入
read -r -sn 1 key
# 处理用户输入
case $key in
"A") # 上箭头
if [ $selected_index -gt 0 ]; then
selected_index=$((selected_index - 1))
fi
;;
"B") # 下箭头
if [ $selected_index -lt $(( ${#options[@]} - 1 )) ]; then
selected_index=$((selected_index + 1))
fi
;;
""|" ") # 回车键或空格键
break
;;
"q") # 按 'q' 键退出
clear
echo "退出"
exit
;;
esac
# 清除屏幕
clear
done
# 用户选择的选项
selected_option="${options[selected_index]}"
send_info $selected_option
if [ "$selected_option" == "选项一" ]; then
echo "选项一"
elif [ "$selected_option" == "选项二" ]; then
echo "选项二"
fi
}
Button

37
File/Shell/cgroup.sh Normal file
View File

@@ -0,0 +1,37 @@
set -e
# 这句是告诉bash如何有任何语句执行结果不为ture就应该退出。
if grep -v '^#' /etc/fstab | grep -q cgroup; then
echo 'cgroups mounted from fstab, not mounting /sys/fs/cgroup'
exit 0
fi
# kernel provides cgroups?
if [ ! -e /proc/cgroups ]; then
exit 0
fi
# 确保目录存在
if [ ! -d /sys/fs/cgroup ]; then
exit 0
fi
# mount /sys/fs/cgroup if not already done
if ! mountpoint -q /sys/fs/cgroup; then
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
fi
cd /sys/fs/cgroup
# get/mount list of enabled cgroup controllers
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
mkdir -p $sys
if ! mountpoint -q $sys; then
if ! mount -n -t cgroup -o $sys cgroup $sys; then
rmdir $sys || true
fi
fi
done
exit 0

View File

@@ -0,0 +1,21 @@
#!/bin/bash
#############################################################################################
# 用途: 使用 Sysstat 工具检测 CPU 负载
# 作者: 丁辉
# 更新时间: 2024-05-10
#############################################################################################
# 获取 CPU 使用情况
cpu_usage=$(mpstat 1 1 | awk '/Average:/ {print 100 - $12}')
# 输出 CPU 使用率
echo "当前 CPU 使用率为: $cpu_usage%"
# 根据需要设置 CPU 使用率的阈值
threshold=80
# 检查 CPU 使用率是否超过阈值
if (( $(echo "$cpu_usage > $threshold" | bc -l) )); then
echo "警告: CPU 使用率超过 ${threshold}%!"
fi

48
File/Shell/check-cpu.sh Normal file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
#############################################################################################
# 用途: 检测 CPU 负载
# 作者: 丁辉
# 更新时间: 2024-05-10
#############################################################################################
# 获取第一次 CPU 时间统计
read -a stats1 < /proc/stat
# 第一次统计的总 CPU 时间
total1=0
for i in {1..4}; do
total1=$((total1 + ${stats1[i]}))
done
# 第一次统计的空闲 CPU 时间
idle1=${stats1[4]}
# 等待一个时间间隔
sleep 1
# 获取第二次 CPU 时间统计
read -a stats2 < /proc/stat
# 第二次统计的总 CPU 时间
total2=0
for i in {1..4}; do
total2=$((total2 + ${stats2[i]}))
done
# 第二次统计的空闲 CPU 时间
idle2=${stats2[4]}
# 计算总的 CPU 时间差和空闲 CPU 时间差
total=$((total2 - total1))
idle=$((idle2 - idle1))
# 避免除零错误
if [ $total -ne 0 ]; then
cpu_usage=$((100 * (total - idle) / total))
else
cpu_usage=0
fi
# 输出 CPU 使用率
echo "当前 CPU 使用率为: $cpu_usage%"

View File

@@ -0,0 +1,27 @@
#!/bin/bash
#############################################################################################
# 用途: Mysql 数据库备份脚本
# 作者: 丁辉
# 更新时间: 2024-05-20
#############################################################################################
# crontab -e
# 0 2 * * * bash /opt/mysql/backup/mysql-backup.sh
MYSQL_HOST=<MYSQL_HOST>
MYSQL_USER=root
MYSQL_PASS=root
BACKDIRPATH=/opt/mysql/backup
DATE=`date +%F%H%M`
# 填写需要备份的数据库
databases=(
database
)
for DATABASE in ${databases[@]};do
docker run --rm mysql:8.0 mysqldump -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASS} ${DATABASE} > ${BACKDIRPATH}/${DATABASE}-${DATE}.sql
tar zcf ${BACKDIRPATH}/${DATABASE}-${DATE}.tar ${BACKDIRPATH}/${DATABASE}-${DATE}.sql
done
find ${BACKUP_DIR} -name "rainbond-*.sql.gz" -type f -mtime +30 -exec rm {} \; > /dev/null 2>&1

39
File/Shell/nginx-ssl.sh Normal file
View File

@@ -0,0 +1,39 @@
#!/bin/sh
#############################################################################################
# 用途: Nginx 签发证书脚本
# 作者: 丁辉
# 更新时间: 2024-05-20
#############################################################################################
read -p "输入您的域名: " DOMAIN
echo "创建服务器密钥..."
openssl genrsa -des3 -out $DOMAIN.key 1024
echo "创建服务器证书签名请求..."
SUBJECT="/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=$DOMAIN"
openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr
echo "移除密码..."
mv $DOMAIN.key $DOMAIN.origin.key
openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key
echo "签署SSL证书..."
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt
echo "待办事项: "
echo "$DOMAIN.crt 复制到 /etc/nginx/ssl/$DOMAIN.crt"
echo "$DOMAIN.key 复制到 /etc/nginx/ssl/$DOMAIN.key"
echo "在nginx中添加配置:"
echo "server {"
echo " ..."
echo " listen 443 ssl;"
echo " ssl_certificate /etc/nginx/ssl/$DOMAIN.crt;"
echo " ssl_certificate_key /etc/nginx/ssl/$DOMAIN.key;"
echo "}"

View File

@@ -0,0 +1,71 @@
#!/bin/bash
#############################################################################################
# 用途: 生成 Docker 远程证书生成脚本
# 作者: 丁辉
# 编写时间: 2024-01-03
#############################################################################################
# 加载检测脚本
source <(curl -sS https://gitee.com/offends/Shell/raw/main/Check_command.sh)
# 定义变量
IP="127.0.0.1"
PASSWORD="123456"
VALIDITY_PERIOD=3650
SEND_INFO "开始生成 Docker 远程证书,请稍等..."
CHECK_DIR "/usr/local/ca"
cd /usr/local/ca
# 生成 CA 私钥
openssl genrsa -aes256 -passout pass:"$PASSWORD" -out ca-key.pem 4096
# 生成 CA 证书
openssl req -new -x509 -days $VALIDITY_PERIOD -key ca-key.pem -passin pass:"$PASSWORD" -sha256 -out ca.pem -subj "/C=CN/ST=./L=./O=./CN=$IP"
# 生成服务器私钥
openssl genrsa -out server-key.pem 4096
# 生成服务器证书签名请求
openssl req -subj "/CN=$IP" -sha256 -new -key server-key.pem -out server.csr
# 生成服务器证书
echo subjectAltName = IP:$IP,IP:0.0.0.0 >> server.cnf
openssl x509 -req -days $VALIDITY_PERIOD -sha256 -in server.csr -CA ca.pem -CAkey ca-key.pem -passin "pass:$PASSWORD" -CAcreateserial -out server-cert.pem -extfile server.cnf
# 生成客户端私钥
openssl genrsa -out key.pem 4096
# 生成客户端证书签名请求
openssl req -subj '/CN=client' -new -key key.pem -out client.csr
# 生成客户端证书
echo extendedKeyUsage = clientAuth >> server.cnf
echo extendedKeyUsage = clientAuth > server-client.cnf
openssl x509 -req -days $VALIDITY_PERIOD -sha256 -in client.csr -CA ca.pem -CAkey ca-key.pem -passin "pass:$PASSWORD" -CAcreateserial -out cert.pem -extfile server-client.cnf
# 清理文件
rm -rf client.csr server.csr server.cnf server-client.cnf
# 修改权限
chmod 0400 ca-key.pem key.pem server-key.pem
chmod 0444 ca.pem server-cert.pem cert.pem
SEND_INFO "Docker 远程证书生成完毕,正在移动目录请稍等..."
CHECK_DIR "/etc/docker/cert/2375/"
cp server-*.pem /etc/docker/cert/2375/
cp ca.pem /etc/docker/cert/2375/
rm -rf /usr/local/ca/
SEND_INFO "Docker 远程证书移动完毕,请手动配置 Docker 远程证书路径为 /etc/docker/cert/2375/"

View File

@@ -0,0 +1,85 @@
#!/bin/bash
#############################################################################################
# 用途: inotify 同步脚本
# 作者: 丁辉
# 更新时间: 2024-03-28
#############################################################################################
# rsync 服务端 IP
HOST=none
# rsync 用户名
USER=rsync
# rsync 密码文件
PASSWORD=/etc/rsync.pass
# 同步目录
SRC=/data/
# rsync 模块
Module=data
# inotifywait 命令
inotifywait=/usr/bin/inotifywait
#### Inotifywait 参数解释
# -m: 监控目录
# -r: 递归监控
# -q: 静默模式
# --timefmt: 时间格式
# %Y: 年
# %m: 月
# %d: 日
# %H: 时
# %M: 分
# --format: 输出格式
# %T: 时间
# %w: 目录
# %f: 文件
# %e: 事件
# %Xe: 扩展事件
# -e: 监控事件
# modify: 文件内容修改
# delete: 文件删除
# create: 文件创建
# attrib: 文件属性修改
# move: 文件移动
# close_write: 文件关闭写入
##### Rsync 参数解释
# -a: 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
# -r: 相对路径传输文件
# -t: 保持文件时间信息
# -u: 仅传输更新文件
# -z: 传输时压缩
# -v: 详细模式输出
# -c: 跳过校验算法,仅根据文件时间和大小判断是否同步
# -P: 保持文件传输进度
# 监控目录
cd $SRC
$inotifywait -mrq --timefmt '%Y%m%d %H:%M' --format '%T %w%f %Xe' -e modify,delete,create,attrib,move,close_write ./ \
| while read files ;do
# 获取文件路径
FILE_PWD=$(echo $files | awk '{print $3}')
# 获取文件事件
FILE_EVENT=$(echo $files | awk '{print $4}')
# 在日志内提示时间
echo ".....................................$(date)....................................."
# 增加、修改、写入完成、移动进事件
if [[ $FILE_EVENT =~ "CREATE" ]] || [[ $FILE_EVENT =~ "MODIFY" ]] || [[ $FILE_EVENT =~ "CLOSE_WRITE" ]] || [[ $FILE_EVENT =~ "MOVED_TO" ]]; then
rsync -artuz --password-file=${PASSWORD} $(dirname ${FILE_PWD}) ${USER}@${HOST}::${Module}
fi
# 删除、移动事件触发
if [[ $FILE_EVENT =~ "DELETE" ]] || [[ $FILE_EVENT =~ "MOVED_FROM" ]]; then
rsync -artuz --password-file=${PASSWORD} $(dirname ${FILE_PWD}) ${USER}@${HOST}::${Module}
fi
# 修改属性事件触发[ touch, chgrp, chmod, chown ]
if [[ $FILE_EVENT =~ "ATTRIB" ]]; then
# 判断是否为目录, 如果是目录则不同步(在目录下文件修改属性时, 目录属性也会被修改)
if [ ! -d "$INO_FILE" ]; then
rsync -artuz --password-file=${PASSWORD} $(dirname ${FILE_PWD}) ${USER}@${HOST}::${Module}
fi
fi
done

View File

@@ -0,0 +1,921 @@
#!/usr/bin/env bash
# shellcheck disable=SC1117
# Ubuntu Kernel PPA info
ppa_host="kernel.ubuntu.com"
ppa_index="/~kernel-ppa/mainline/"
ppa_key="17C622B0"
# Machine-Owner-Key for Secure Boot
sign_kernel=0
mokKey="/var/lib/shim-signed/mok/MOK-Kernel.priv"
mokCert="/var/lib/shim-signed/mok/MOK-Kernel.pem"
self_update_url="https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh"
# If quiet=1 then no log messages are printed (except errors)
quiet=0
# If check_signature=0 then the signature of the CHECKSUMS file will not be checked
check_signature=1
# If check_checksum=0 then the checksums of the .deb files will not be checked
check_checksum=1
# If doublecheckversion=1 then also check the version specific ppa page to make
# sure the kernel build was successful
doublecheckversion=1
# Connect over http or https to ppa (only https works)
use_https=1
# Path to sudo command, empty by default
sudo=""
#sudo=$(command -v sudo) # Uncomment this line if you dont want to sudo yourself
# Path to wget command
wget=$(command -v wget)
#####
## Below are internal variables of which most can be toggled by command options
## DON'T CHANGE THESE MANUALLY
#####
# (internal) If cleanup_files=1 then before exiting all downloaded/temporaryfiles
# are removed
cleanup_files=1
# (internal) If do_install=0 downloaded deb files will not be installed
do_install=1
# (internal) If use_lowlatency=1 then the lowlatency kernel will be installed
use_lowlatency=0
# (internal) If use_lpae=1 then the lpae kernel will be installed
use_lpae=0
# (internal) If use_snapdragon=1 then the snapdragon kernel will be installed
use_snapdragon=0
# (internal) If use_rc=1 then release candidate kernel versions are also checked
use_rc=0
# (internal) If assume_yes=1 assume yes on all prompts
assume_yes=0
# (internal) How many files we expect to retrieve from the ppa
# checksum, signature, header-all, header-arch, image(-unsigned), modules
expected_files_count=6
# (internal) Which action/command the script should run
run_action="help"
# (internal) The workdir where eg the .deb files are downloaded
workdir="/tmp/$(basename "$0")/"
# (internal) The stdio where all detail output should be sent
debug_target="/dev/null"
# (internal) Holds all version numbers of locally installed ppa kernels
LOCAL_VERSIONS=()
# (internal) Holds all version numbers of available ppa kernels
REMOTE_VERSIONS=()
# (internal) The architecture of the local system
arch=$(dpkg --print-architecture)
# (internal) The text to search for to check if the build was successfully
# NOTE: New succeed text since v5.6.18
build_succeeded_text="(Build for ${arch} succeeded|Test ${arch}/build succeeded)"
# (internal) The pid of the child process which checks download progress
monitor_pid=0
# (internal) The size of the file which is being downloaded
download_size=0
action_data=()
#####
## Check if we are running on an Ubuntu-like OS
#####
# shellcheck disable=SC1091,SC2015
[ -f "/etc/os-release" ] && {
source /etc/os-release
[[ "$ID" == "ubuntu" ]] || [[ "$ID_LIKE" =~ "ubuntu" ]]
} || {
OS=$(lsb_release -si 2>&-)
[[ "$OS" == "Ubuntu" ]] || [[ "$OS" == "LinuxMint" ]] || [[ "$OS" == "neon" ]] || {
echo "Abort, this script is only intended for Ubuntu-like distros"
exit 2
}
}
#####
## helper functions
#####
single_action () {
[ "$run_action" != "help" ] && {
err "Abort, only one argument can be supplied. See -h"
exit 2
}
}
log () {
[ $quiet -eq 0 ] && echo "$@"
}
logn () {
[ $quiet -eq 0 ] && echo -n "$@"
}
warn () {
[ $quiet -eq 0 ] && echo "$@" >&2
}
err () {
echo "$@" >&2
}
#####
## Simple command options parser
#####
while (( "$#" )); do
argarg_required=0
case $1 in
-c|--check)
single_action
run_action="check"
;;
-l|--local-list)
single_action
run_action="local-list"
argarg_required=1
;;
-r|--remote-list)
single_action
run_action="remote-list"
argarg_required=1
;;
-i|--install)
single_action
run_action="install"
argarg_required=1
;;
-u|--uninstall)
single_action
run_action="uninstall"
argarg_required=1
;;
-p|--path)
if [ -z "$2" ] || [ "${2##-}" != "$2" ]; then
err "Option $1 requires an argument."
exit 2
else
workdir="$(realpath "$2")/"
shift
if [ ! -d "$workdir" ]; then
mkdir -p "$workdir";
fi
if [ ! -d "$workdir" ] || [ ! -w "$workdir" ]; then
err "$workdir is not writable"
exit 1
fi
cleanup_files=0
fi
;;
-ll|--lowlatency|--low-latency)
[[ "$arch" != "amd64" ]] && [[ "$arch" != "i386" ]] && {
err "Low-latency kernels are only available for amd64 or i386 architectures"
exit 3
}
use_lowlatency=1
;;
-lpae|--lpae)
[[ "$arch" != "armhf" ]] && {
err "Large Physical Address Extension (LPAE) kernels are only available for the armhf architecture"
exit 3
}
use_lpae=1
;;
--snapdragon)
[[ "$arch" != "arm64" ]] && {
err "Snapdragon kernels are only available for the arm64 architecture"
exit 3
}
use_snapdragon=1
;;
--rc)
use_rc=1
;;
-s|--signed)
log "The option '--signed' is not yet implemented"
;;
--yes)
assume_yes=1
;;
-q|--quiet)
[ "$debug_target" == "/dev/null" ] && { quiet=1; }
;;
-do|--download-only)
do_install=0
cleanup_files=0
;;
-ns|--no-signature)
check_signature=0
;;
-nc|--no-checksum)
check_checksum=0
;;
-d|--debug)
debug_target="/dev/stderr"
quiet=0
;;
--update)
run_action="update"
;;
-h|--help)
run_action="help"
;;
*)
run_action="help"
err "Unknown argument $1"
;;
esac
if [ $argarg_required -eq 1 ]; then
[ -n "$2" ] && [ "${2##-}" == "$2" ] && {
action_data+=("$2")
shift
}
elif [ $argarg_required -eq 2 ]; then
# shellcheck disable=SC2015
[ -n "$2" ] && [ "${2##-}" == "$2" ] && {
action_data+=("$2")
shift
} || {
err "Option $1 requires an argument"
exit 2
}
fi
shift
done
#####
## internal functions
#####
containsElement () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] || [[ "$e" =~ $1- ]] && return 0; done
return 1
}
download () {
host=$1
uri=$2
if [ $use_https -eq 1 ]; then
$wget -q --save-headers --output-document - "https://$host$uri"
else
exec 3<>/dev/tcp/"$host"/80
echo -e "GET $uri HTTP/1.0\r\nHost: $host\r\nConnection: close\r\n\r\n" >&3
cat <&3
fi
}
monitor_progress () {
local msg=$1
local file=$2
download_size=-1
printf "%s: " "$msg"
(while :; do for c in / - \\ \|; do
[[ -f "$file" ]] && {
# shellcheck disable=SC2015
[[ $download_size -le 0 ]] && {
download_size=$(($(head -n20 "$file" | grep -aoi -E "Content-Length: [0-9]+" | cut -d" " -f2) + 0))
printf ' %d%% %s' 0 "$c"
printf '\b%.0s' {1..5}
} || {
filesize=$(( $(du -b "$file" | cut -f1) + 0))
progress="$((200*filesize/download_size % 2 + 100*filesize/download_size))"
printf ' %s%% %s' "$progress" "$c"
length=$((4 + ${#progress}))
printf '\b%.0s' $(seq 1 $length)
}
}
sleep 1
done; done) &
monitor_pid=$!
}
end_monitor_progress () {
{ kill $monitor_pid && wait $monitor_pid; printf '100%% \n'; } 2>/dev/null
}
remove_http_headers () {
file="$1"
nr=0
while(true); do
nr=$((nr + 1))
line=$(head -n$nr "$file" | tail -n 1)
if [ -z "$(echo "$line" | tr -cd '\r\n')" ]; then
tail -n +$nr "$file" > "${file}.tmp"
mv "${file}.tmp" "${file}"
break
fi
[ $nr -gt 100 ] && {
err "Abort, could not remove http headers from file"
exit 3
}
done
}
load_local_versions() {
local version
if [ ${#LOCAL_VERSIONS[@]} -eq 0 ]; then
IFS=$'\n'
for pckg in $(dpkg -l linux-image-* | cut -d " " -f 3 | sort -V); do
# only match kernels from ppa
if [[ "$pckg" =~ linux-image-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then
version="v"$(echo "$pckg" | cut -d"-" -f 3,4)
LOCAL_VERSIONS+=("$version")
fi
done
unset IFS
fi
}
latest_local_version() {
load_local_versions 1
if [ ${#LOCAL_VERSIONS[@]} -gt 0 ]; then
local sorted
mapfile -t sorted < <(echo "${LOCAL_VERSIONS[*]}" | tr ' ' '\n' | sort -t"." -k1V,3)
lv="${sorted[${#sorted[@]}-1]}"
echo "${lv/-[0-9][0-9][0-9][0-9][0-9][0-9]rc/-rc}"
else
echo "none"
fi
}
remote_html_cache=""
parse_remote_versions() {
local line
while read -r line; do
if [[ $line =~ DIR.*href=\"(v[[:digit:]]+\.[[:digit:]]+(\.[[:digit:]]+)?)(-(rc[[:digit:]]+))?/\" ]]; then
line="${BASH_REMATCH[1]}"
if [[ -z "${BASH_REMATCH[2]}" ]]; then
line="$line.0"
fi
# temporarily substitute rc suffix join character for correct version sort
if [[ -n "${BASH_REMATCH[3]}" ]]; then
line="$line~${BASH_REMATCH[4]}"
fi
echo "$line"
fi
done <<<"$remote_html_cache"
}
load_remote_versions () {
local line
[[ -n "$2" ]] && {
REMOTE_VERSIONS=()
}
if [ ${#REMOTE_VERSIONS[@]} -eq 0 ]; then
if [ -z "$remote_html_cache" ]; then
[ -z "$1" ] && logn "Downloading index from $ppa_host"
remote_html_cache=$(download $ppa_host $ppa_index)
[ -z "$1" ] && log
fi
if [ -n "$remote_html_cache" ]; then
IFS=$'\n'
while read -r line; do
# reinstate original rc suffix join character
if [[ $line =~ ^([^~]+)~([^~]+)$ ]]; then
[[ $use_rc -eq 0 ]] && continue
line="${BASH_REMATCH[1]}-${BASH_REMATCH[2]}"
fi
[[ -n "$2" ]] && [[ ! "$line" =~ $2 ]] && continue
REMOTE_VERSIONS+=("$line")
done < <(parse_remote_versions | sort -V)
unset IFS
fi
fi
}
latest_remote_version () {
load_remote_versions 1 "$1"
if [ ${#REMOTE_VERSIONS[@]} -gt 0 ]; then
echo "${REMOTE_VERSIONS[${#REMOTE_VERSIONS[@]}-1]}"
else
echo ""
fi
}
check_environment () {
if [ $use_https -eq 1 ] && [ -z "$wget" ]; then
err "Abort, wget not found. Please apt install wget"
exit 3
fi
}
guard_run_as_root () {
if [ "$(id -u)" -ne 0 ]; then
echo "The '$run_action' command requires root privileges"
exit 2
fi
}
# execute requested action
case $run_action in
help)
echo "Usage: $0 -c|-l|-r|-u
Download & install the latest kernel available from $ppa_host$ppa_uri
Arguments:
-c Check if a newer kernel version is available
-i [VERSION] Install kernel VERSION, see -l for list. You don't have to prefix
with v. E.g. -i 4.9 is the same as -i v4.9. If version is
omitted the latest available version will be installed
-l [SEARCH] List locally installed kernel versions. If an argument to this
option is supplied it will search for that
-r [SEARCH] List available kernel versions. If an argument to this option
is supplied it will search for that
-u [VERSION] Uninstall the specified kernel version. If version is omitted,
a list of max 10 installed kernel versions is displayed
--update Update this script by redownloading it from github
-h Show this message
Optional:
-s, --signed Only install signed kernel packages (not implemented)
-p, --path DIR The working directory, .deb files will be downloaded into
this folder. If omitted, the folder /tmp/$(basename "$0")/
is used. Path is relative from \$PWD
-ll, --low-latency Use the low-latency version of the kernel, only for amd64 & i386
-lpae, --lpae Use the Large Physical Address Extension kernel, only for armhf
--snapdragon Use the Snapdragon kernel, only for arm64
-do, --download-only Only download the deb files, do not install them
-ns, --no-signature Do not check the gpg signature of the checksums file
-nc, --no-checksum Do not check the sha checksums of the .deb files
-d, --debug Show debug information, all internal command's echo their output
--rc Also include release candidates
--yes Assume yes on all questions (use with caution!)
"
exit 2
;;
update)
check_environment
self="$(readlink -f "$0")"
$wget -q -O "$self.tmp" "$self_update_url"
if [ ! -s "$self.tmp" ]; then
rm "$self.tmp"
err "Update failed, downloaded file is empty"
exit 1
else
mv "$self.tmp" "$self"
echo "Script updated"
fi
;;
check)
check_environment
logn "Finding latest version available on $ppa_host"
latest_version=$(latest_remote_version)
log ": $latest_version"
if [ -z "$latest_version" ]; then
err "Could not find latest version"
exit 1
fi
logn "Finding latest installed version"
installed_version=$(latest_local_version)
installed_version=${installed_version%-*}
log ": $installed_version"
# Check if build was successful
if [ $doublecheckversion -gt 0 ]; then
ppa_uri=$ppa_index${latest_version%\.0}"/"
ppa_uri=${ppa_uri/\.0-rc/-rc}
index=$(download $ppa_host "$ppa_uri")
if [[ ! $index =~ $build_succeeded_text ]]; then
log "A newer kernel version ($latest_version) was found but the build was not successful"
[ -n "$DISPLAY" ] && [ -x "$(command -v notify-send)" ] && notify-send --icon=info -t 12000 \
"Kernel $latest_version available" \
"A newer kernel version ($latest_version) is\navailable but the build was not successful"
exit 1
fi
fi
# Check installed minor branch
latest_minor_text=""
latest_minor_notify=""
latest_minor_version=""
if [ -n "${installed_version}" ] && [ "${installed_version}" != "none" ] && [ "${latest_version%.*}" != "${installed_version%.*}" ]; then
latest_minor_version=$(latest_remote_version "${installed_version%.*}")
if [ "$installed_version" != "$latest_minor_version" ]; then
latest_minor_text=", latest in current branch is ${latest_minor_version}"
latest_minor_notify="Version ${latest_minor_version} is available in the current ${installed_version%.*} branch\n\n"
fi
fi
if [ "$installed_version" != "$latest_version" ] && [ "$installed_version" = "$(echo -e "$latest_version\n$installed_version" | sort -V | head -n1)" ]; then
log "A newer kernel version ($latest_version) is available${latest_minor_text}"
[ -n "$DISPLAY" ] && [ -x "$(command -v notify-send)" ] && notify-send --icon=info -t 12000 \
"Kernel $latest_version available" \
"A newer kernel version ($latest_version) is available\n\n${latest_minor_notify}Run '$(basename "$0") -i' to update\nor visit $ppa_host$ppa_uri"
exit 1
fi
;;
local-list)
load_local_versions
# shellcheck disable=SC2015
[[ -n "$(command -v column)" ]] && { column="column -x"; } || { column="cat"; }
(for version in "${LOCAL_VERSIONS[@]}"; do
if [ -z "${action_data[0]}" ] || [[ "$version" =~ ${action_data[0]} ]]; then
echo "$version"
fi
done) | $column
;;
remote-list)
check_environment
load_remote_versions
# shellcheck disable=SC2015
[[ -n "$(command -v column)" ]] && { column="column -x"; } || { column="cat"; }
(for version in "${REMOTE_VERSIONS[@]}"; do
if [ -z "${action_data[0]}" ] || [[ "$version" =~ ${action_data[0]} ]]; then
echo "$version"
fi
done) | $column
;;
install)
# only ensure running if the kernel files should be installed
[ $do_install -eq 1 ] && guard_run_as_root
check_environment
load_local_versions
if [ -z "${action_data[0]}" ]; then
logn "Finding latest version available on $ppa_host"
version=$(latest_remote_version)
log
if [ -z "$version" ]; then
err "Could not find latest version"
exit 1
fi
if containsElement "$version" "${LOCAL_VERSIONS[@]}"; then
logn "Latest version is $version but seems its already installed"
else
logn "Latest version is: $version"
fi
if [ $do_install -gt 0 ] && [ $assume_yes -eq 0 ];then
logn ", continue? (y/N) "
[ $quiet -eq 0 ] && read -rsn1 continue
log
[ "$continue" != "y" ] && [ "$continue" != "Y" ] && { exit 0; }
else
log
fi
else
load_remote_versions
version=""
if containsElement "v${action_data[0]#v}" "${REMOTE_VERSIONS[@]}"; then
version="v"${action_data[0]#v}
fi
[[ -z "$version" ]] && {
err "Version '${action_data[0]}' not found"
exit 2
}
shift
if [ $do_install -gt 0 ] && containsElement "$version" "${LOCAL_VERSIONS[@]}" && [ $assume_yes -eq 0 ]; then
logn "It seems version $version is already installed, continue? (y/N) "
[ $quiet -eq 0 ] && read -rsn1 continue
log
[ "$continue" != "y" ] && [ "$continue" != "Y" ] && { exit 0; }
fi
fi
[ ! -d "$workdir" ] && {
mkdir -p "$workdir" 2>/dev/null
}
[ ! -x "$workdir" ] && {
err "$workdir is not writable"
exit 1
}
cd "$workdir" || exit 1
[ $check_signature -eq 1 ] && [ ! -x "$(command -v gpg)" ] && {
check_signature=0
warn "Disable signature check, gpg not available"
}
[[ $sign_kernel -eq 1 && (! -s "$mokKey" || ! -s "$mokCert") ]] && {
err "Could not find machine owner key"
exit 1
}
IFS=$'\n'
ppa_uri=$ppa_index${version%\.0}"/"
ppa_uri=${ppa_uri/\.0-rc/-rc}
index=$(download $ppa_host "$ppa_uri")
if [[ ! $index =~ $build_succeeded_text ]]; then
err "Abort, the ${arch} build has not succeeded"
exit 1
fi
index=${index%%*<table}
FILES=()
found_arch=0
uses_subfolders=0
section_end="^[[:space:]]*<br>[[:space:]]*$"
for line in $index; do
if [[ $line =~ $build_succeeded_text ]]; then
found_arch=1
continue
elif [ $found_arch -eq 0 ]; then
continue
elif [[ $line =~ $section_end ]]; then
break
fi
[[ "$line" =~ linux-(image(-(un)?signed)?|headers|modules)-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6}.*?_(${arch}|all).deb ]] || continue
[ $use_lowlatency -eq 0 ] && [[ "$line" =~ "-lowlatency" ]] && continue
[ $use_lowlatency -eq 1 ] && [[ ! "$line" =~ "-lowlatency" ]] && [[ ! "$line" =~ "_all" ]] && continue
[ $use_lpae -eq 0 ] && [[ "$line" =~ "-lpae" ]] && continue
[ $use_lpae -eq 1 ] && [[ ! "$line" =~ "-lpae" ]] && [[ ! "$line" =~ "_all" ]] && continue
[ $use_snapdragon -eq 0 ] && [[ "$line" =~ "-snapdragon" ]] && continue
[ $use_snapdragon -eq 1 ] && [[ ! "$line" =~ "-snapdragon" ]] && [[ ! "$line" =~ "_all" ]] && continue
line=${line##*href=\"}
line=${line%%\">*}
if [ $uses_subfolders -eq 0 ] && [[ $line =~ ${arch}/linux ]]; then
uses_subfolders=1
fi
FILES+=("$line")
done
unset IFS
if [ $check_signature -eq 1 ]; then
if [ $uses_subfolders -eq 0 ]; then
FILES+=("CHECKSUMS" "CHECKSUMS.gpg")
else
FILES+=("${arch}/CHECKSUMS" "${arch}/CHECKSUMS.gpg")
fi
fi
if [ ${#FILES[@]} -ne $expected_files_count ]; then
if [ $assume_yes -eq 0 ]; then
logn "Expected to need to download $expected_files_count files but found ${#FILES[@]}, continue? (y/N)"
read -rsn1 continue
echo ""
else
continue="y"
fi
[ "$continue" != "y" ] && [ "$continue" != "Y" ] && { exit 0; }
fi
debs=()
log "Will download ${#FILES[@]} files from $ppa_host:"
for file in "${FILES[@]}"; do
workfile=${file##*/}
monitor_progress "Downloading $file" "$workdir$workfile"
download $ppa_host "$ppa_uri$file" > "$workdir$workfile"
remove_http_headers "$workdir$workfile"
end_monitor_progress
if [[ "$workfile" =~ \.deb ]]; then
debs+=("$workfile")
fi
done
if [ $check_signature -eq 1 ]; then
if ! gpg --list-keys ${ppa_key} >$debug_target 2>&1; then
logn "Importing kernel-ppa gpg key "
if gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv ${ppa_key} >$debug_target 2>&1; then
log "ok"
else
logn "failed"
err "Unable to import ppa key"
exit 1
fi
fi
if [ $check_signature -eq 1 ]; then
if gpg --verify CHECKSUMS.gpg CHECKSUMS >$debug_target 2>&1; then
log "Signature of checksum file has been successfully verified"
else
err "Abort, signature of checksum file is NOT OK"
exit 4
fi
fi
fi
if [ $check_checksum -eq 1 ]; then
shasums=( "sha256sum" "sha1sum" )
for shasum in "${shasums[@]}"; do
xshasum=$(command -v "$shasum")
if [ -n "$xshasum" ] && [ -x "$xshasum" ]; then
# shellcheck disable=SC2094
shasum_result=$($xshasum --ignore-missing -c CHECKSUMS 2>>$debug_target | tee -a $debug_target | wc -l)
if [ "$shasum_result" -eq 0 ] || [ "$shasum_result" -ne ${#debs[@]} ]; then
err "Abort, $shasum returned an error $shasum_result"
exit 4
else
log "Checksums of deb files have been successfully verified with $shasum"
fi
break
fi
done
fi
if [ $do_install -eq 1 ]; then
if [ ${#debs[@]} -gt 0 ]; then
log "Installing ${#debs[@]} packages"
$sudo dpkg -i "${debs[@]}" >$debug_target 2>&1
else
warn "Did not find any .deb files to install"
fi
else
log "deb files have been saved to $workdir"
fi
if [ $sign_kernel -eq 1 ]; then
kernelImg=""
for deb in "${debs[@]}"; do
# match deb file that starts with linux-image-
if [[ "$deb" == "linux-image-"* ]]; then
imagePkgName="${deb/_*}"
# The image deb normally only adds one file (the kernal image) to
# the /boot folder, find it so we can sign it
kernelImg="$(grep /boot/ <<< "$(dpkg -L "$imagePkgName")")"
fi
done
if [ -n "$kernelImg" ] && [ -x "$(command -v sbsign)" ]; then
if $sudo sbverify --cert "$mokCert" "$kernelImg" >/dev/null; then
echo "Kernel image $kernelImg is already signed by the provided MOK"
elif $sudo sbverify --list "$kernelImg" | grep -v "No signature table present"; then
echo "Kernel image $kernelImg is already signed by another MOK"
else
echo -n "Signing kernel image"
$sudo sbsign --key "$mokKey" --cert "$mokCert" --output "$kernelImg" "$kernelImg"
echo ""
fi
fi
fi
if [ $cleanup_files -eq 1 ]; then
log "Cleaning up work folder"
rm -f "$workdir"*.deb
rm -f "$workdir"CHECKSUM*
rmdir "$workdir"
fi
;;
uninstall)
guard_run_as_root
load_local_versions
if [ ${#LOCAL_VERSIONS[@]} -eq 0 ]; then
echo "No installed mainline kernels found"
exit 1
elif [ -z "${action_data[0]}" ]; then
echo "Which kernel version do you wish to uninstall?"
nr=0
for version in "${LOCAL_VERSIONS[@]}"; do
echo "[$nr]: $version"
nr=$((nr + 1))
[ $nr -gt 9 ] && break
done
echo -n "type the number between []: "
read -rn1 index
echo ""
if ! [[ $index == +([0-9]) ]]; then
echo "No number entered, exiting"
exit 0
fi
uninstall_version=${LOCAL_VERSIONS[$index]}
if [ -z "$uninstall_version" ]; then
echo "Version not found"
exit 0
fi
elif containsElement "v${action_data[0]#v}" "${LOCAL_VERSIONS[@]}"; then
uninstall_version="v"${action_data[0]#v}
else
err "Kernel version ${action_data[0]} not installed locally"
exit 2
fi
if [ $assume_yes -eq 0 ]; then
echo -n "Are you sure you wish to remove kernel version $uninstall_version? (y/N)"
read -rsn1 continue
echo ""
else
continue="y"
fi
if [ "$continue" == "y" ] || [ "$continue" == "Y" ]; then
IFS=$'\n'
pckgs=()
for pckg in $(dpkg -l linux-{image,image-[un]?signed,headers,modules}-"${uninstall_version#v}"* 2>$debug_target | cut -d " " -f 3); do
# only match kernels from ppa, they have 6 characters as second version string
if [[ "$pckg" =~ linux-headers-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then
pckgs+=("$pckg:$arch")
pckgs+=("$pckg:all")
elif [[ "$pckg" =~ linux-(image(-(un)?signed)?|modules)-[0-9]+\.[0-9]+\.[0-9]+-[0-9]{6} ]]; then
pckgs+=("$pckg:$arch")
fi
done
if [ ${#pckgs[@]} -eq 0 ]; then
warn "Did not find any packages to remove"
else
echo "The following packages will be removed: "
echo "${pckgs[@]}"
if [ $assume_yes -eq 0 ]; then
echo -n "Are you really sure? Do you still have another kernel installed? (y/N)"
read -rsn1 continue
echo ""
else
continue="y"
fi
if [ "$continue" == "y" ] || [ "$continue" == "Y" ]; then
if $sudo env DEBIAN_FRONTEND=noninteractive dpkg --purge "${pckgs[@]}" 2>$debug_target >&2; then
log "Kernel $uninstall_version successfully purged"
exit 0
fi
fi
fi
fi
;;
esac
exit 0

85
File/Xml/confxml.xml Normal file
View File

@@ -0,0 +1,85 @@
<!--
作者: 丁辉
-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/> <!--是否为xfs文件系统-->
<filter start="false"> <!--过滤器-->
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<!--当文件或目录被删除时,是否同步-->
<delete start="true"/>
<!--当文件或目录被创建时, 是否同步-->
<createFolder start="true"/>
<!--当文件被创建时, 如果远程目录下有同名文件, 则覆盖远程文件-->
<createFile start="false"/>
<!--在同步任务启动时, 关闭写入操作进行同步-->
<closeWrite start="true"/>
<!--当文件被移动时, 是否同步移动远程文件-->
<moveFrom start="true"/>
<!--将源目录中的文件移动到临时目录-->
<moveTo start="true"/>
<!--将临时目录中的文件移动到目标目录-->
<attrib start="true"/>
<!--在启动时, 是否同步所有文件-->
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/data"> <!--同步的本地目录-->
<remote ip="127.0.0.1" name="data"/>
<!--<remote ip="192.168.1.30" name="data"/>-->
<!--<remote ip="192.168.1.40" name="data"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<!--
params 参数解释
-a: 表示归档模式, 用于保留文件的属性 (包括权限、所有者等) 以及递归复制子目录
-r: 表示递归复制目录和子目录
-t: 表示保留文件的时间戳信息
-u: 表示仅复制更新过的文件
-z: 表示启用压缩传输, 以减少数据传输的大小
-->
<auth start="true" users="rsync" passwordfile="/etc/rsync.pass"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<!--下面是插件的配置-->
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>

128
Git/GIt的使用.md Normal file
View File

@@ -0,0 +1,128 @@
> 本文作者:丁辉
# GIt的使用
[官网](https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA%E4%B8%8E%E5%90%88%E5%B9%B6)
## 基础命令
- 新建分支
```bash
git branch demo
```
- 切换分支
```bash
git checkout demo
```
- 新建并切换到新分支
```bash
git checkout -b demo
```
- 合并分支
```bash
git merge hotfix
```
- 删除分支
```bash
git branch -d hotfix
```
- 查看状态
```bash
git status
```
- 启动一个合适的可视化合并工具
```bash
git mergetool
```
- 添加仓库
```bash
git remote add origins Git地址
```
- 拉取代码
```bash
git pull origins
```
- 查看提交信息
```bash
git log
```
- 回滚代码
```bash
git reset --hard ID信息
```
- 不回滚已修改的代码
```bash
git reset ID信息
```
- 清楚缓存
```bash
git credential-cache exit
```
## 跨分支合并某个提交记录
> 例子:假如我有 A 、B 分支
1. 切换到 A 分支
```bash
git checkout <A分支>
```
2. 查看提交日志拿到值
```bash
git log
```
3. 切换到 B 分支
```bash
git checkout <B分支>
```
4. 合并
```bash
git cherry-pick '获取到的提交记录值'
```
5. 检查提交记录,查看是否将 A 文件合并到了 B 仓库
```bash
git log
```
6. 提交文件
```bash
git add .
git push
```

View File

@@ -0,0 +1,34 @@
> 本文作者:丁辉
# Git免密拉取代码
## 第一种
1. 生成密钥
```bash
ssh-keygen
```
2. 查看密钥
```bash
cat ~/.ssh/id_rsa.pub
```
2. 到代码仓库配置 SSH 密钥直接 git clone 免密拉取
## 第二种
在命令里使用账号密码或令牌拉取
```bash
git clone -b main --depth=1 https://$GIT_USERNAME:$GIT_PASSWORD@github.com/offends/demo.git
```
```bash
git clone -b main --depth=1 https://$GIT_TOKEN@github.com/offends/demo.git
```

View File

@@ -0,0 +1,42 @@
> 作者:丁辉
# 清除GitHub中的所有提交历史记录
1. 创建了一个新的分支
```bash
git checkout --orphan latest_branch
```
2. 添加所有文件
```bash
git add -A
```
3. 提交更改
```bash
git commit -am "commit message"
```
4. 删除分支
```bash
git branch -D main
```
5. 将当前分支重命名
```bash
git branch -m main
```
6. 最后,强制更新存储库
```bash
git push -f origin main
```

View File

@@ -0,0 +1,30 @@
> 本文作者:丁辉
# Git配置本地代理
> 本地启动代理后,使用命令更改端口
```bash
# socks5协议1080端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
# http协议1081端口修改成自己的本地代理端口
git config --global http.https://github.com.proxy https://127.0.0.1:1081
git config --global https.https://github.com.proxy https://127.0.0.1:1081
```
- 查看所有配置
```bash
git config -l
```
- 取消 reset 代理设置
```bash
git config --global --unset http.proxy
git config --global --unset https.proxy
```

20
README.md Normal file
View File

@@ -0,0 +1,20 @@
*
> 本文作者:丁辉
# Linux
> 目录详情
| 文件夹名 | 内容 |
| :----------: | :------------------------------------: |
| Docs | Linux系统使用文档 |
| File | 存放各文档内部需要使用的脚本或配置文件 |
| Git | Git使用文档 |
| Shell | Shell使用文档 |
| 存储 | 存储部署、使用文档 |
| 数据库 | 数据库部署、使用文档 |
| 系统安装文档 | 系统安装文档存放目录 |
| 资源安装 | Linux相关软件部署文档 |
| 问题记录 | Linux学习过程中遇到的疑难杂症 |

113
Shell/README.md Normal file
View File

@@ -0,0 +1,113 @@
> 本文作者:丁辉
# 引用外部函数脚本
## 使用
**SHELL 脚本内加入**
```bash
#!/bin/bash
# 加载检测脚本
source <(curl -sS https://gitee.com/offends/Linux/raw/main/File/Shell/Check_command.sh)
```
## 函数介绍
| 函数 | 介绍 | 用法 |
| :--------------------: | :----------------------------------------------------------: | :------------------------------: |
| SEND_INFO | 输出绿色字体INFO信息 | SEND_INFO "你好" |
| SEND_WARN | 输出黄色字体WARN信息 | SEND_WARN "你好" |
| SEND_ERROR | 输出红色字体ERROR信息 | SEND_ERROR "你好" |
| GREEN_PRINTF | print输出绿色字体 | GREEN_PRINTF "你好" |
| FUNC_PRINT_SYSTEM_INFO | 打印系统信息(包含: 系统版本、内核版本、内存大小、处理器核数、处理器型号) | FUNC_PRINT_SYSTEM_INFO |
| CHECK_NETWORK | 检查服务器网络连接(没网则退出) | CHECK_NETWORK |
| CHECK_FILE | 检测文件是否存在 | CHECK_FILE "./demo.sh" |
| CHECK_FILES | 检测文件是否存在(多文件情况) | CHECK_FILES "all-*.rpm" |
| CHECK_DIR | 检测目录是否存在,不存在则创建 | CHECK_DIR "/root/demo" |
| CHECK_BIN | 检测固定位置的二进制文件是否存在(~禁用) | CHECK_BIN "/root/dmeo" |
| CHECK_COMMAND_TRUE | 检测命令是否执行正确,正确则输出$1,错误则输出$2并退出脚本 | CHECK_COMMAND_TRUE "正确" "错误" |
| CHECK_USER | 判断用户是否存在,不存在则创建 | CHECK_USER docker |
| CHECK_GROUP | 判断用户组是否存在,不存在则创建 | CHECK_GROUP docker |
| ADD_USER_GROUP | 用户加入组 | ADD_USER_GROUP docker docker |
| NULL_TRUE | 定义输出为空,并且失败不会退出脚本 | NULL_TRUE ls |
| NULL_TRUE_ECHO | 失败不会退出脚本,输出命令执行结果 | NULL_TRUE_ECHO ls |
| CHECK_COMMAND_NULL | 检测命令是否执行成功,不输出命令执行结果 | CHECK_COMMAND_NULL ls |
| CHECK_COMMAND_ECHO | 检测命令是否执行成功,输出命令执行结果 | CHECK_COMMAND_ECHO ls |
| CHECK_INSTALL | 检测网络安装软件(支持多参数) | CHECK_INSTALL wget git |
| CHECK_SYSTEMD | 检测某个systemd服务是否存在,不存在则退出 | CHECK_SYSTEMD docker |
## 其他参数
- **CHECK_CPU**
**用法**
```bash
#!/bin/bash
CHECK_CPU
```
**变量定义**
> 脚本会自动检测系统架构,并输出变量
>
> 例:
>
> 解释: 如果系统架构为 x86_64 则脚本会给 ARCH_TYPE_1 赋值为 x86_64,这时你可以直接引用 ARCH_TYPE_1 作为下载参数等动态变量
| 变量 | 参数 |
| :---------: | :---------------: |
| ARCH_TYPE_1 | x86_64 或 aarch64 |
| ARCH_TYPE_2 | amd64 或 arm64 |
- **CHECK_OS**
**检查服务器系统版本**
> OS 会被脚本赋值为系统版本,OS_VERSION 会被脚本赋值为系统大版本号
- **CHECK_CORE**
> 内核检测脚本
配置一键默认升级
```bash
CHECK_CORE ALL_DEFAULT_YES=1
```
- 内核升级
[内核升级脚本](https://gitee.com/offends/Linux/blob/main/File/Shell/Core.sh)
- 在线升级
执行脚本
```bash
./Core.sh
```
> 配置一键默认升级
>
> ```bash
> export ALL_DEFAULT_YES=1
> ```
- 离线包打包
[离线打包脚本](https://gitee.com/offends/Linux/blob/main/File/Shell/Build_Core_Tar.sh)
> 脚本为: Build_Core_Tar.sh
**参数**
| 参数 | 解释 | 用法 |
| :-----: | :-------------------: | :-------------------------: |
| Centos7 | 打包Centos7内核离线包 | ./Build_Core_Tar.sh Centos7 |
| Centos8 | 打包Centos8内核离线包 | ./Build_Core_Tar.sh Centos8 |
| Ubuntu | 打包Centos8内核离线包 | ./Build_Core_Tar.sh Ubuntu |

View File

@@ -0,0 +1,49 @@
> 本文作者:丁辉
[官方下载地址](http://www.datsi.fi.upm.es/~frosal/)
# Shell脚本加密Shc
## Shc源码部署
1. 下载
```bash
wget http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.9b.tgz
```
2. 解压
```bash
tar -zxvf shc-*.tgz && cd shc-*
```
3. 安装 `gcc 和 make` 后编译
```bash
make && mv shc /usr/local/bin/
```
## Shc网络源部署
- Centos安装
```bash
yum -y install shc
```
- Ubuntu安装
```bash
apt -y install shc
```
**shc参数**
| 参数 | 解释 | 使用示例 |
| :--: | :------------------------------: | :-----------------------------------------------: |
| -e | 指定过期时间 | shc -e 06/09/2023 -f demo.sh |
| -m | 过期后打印出的信息 | shc -e 06/09/2023 -m "File is expired" -f demo.sh |
| -v | 输出verbose 过程信息 | shc -v -f demo.sh |
| -r | 可在相同操作系统的不同主机上执行 | shc -r demo.sh |
| -f | 指定源shell | shc -f demo.sh |

View File

@@ -0,0 +1,110 @@
> 本文作者:丁辉
# Shell脚本集合记录
## Shell里有 Read 如何默认回车?
- 示例一
```bash
#!/bin/bash
defaultValue="默认值"
# 如果没有输入,使用默认值
read userInput
userInput=${userInput:-$defaultValue}
echo "你输入的内容是:$userInput"
```
执行脚本
```bash
bash shell.sh <<< ""
```
- 示例二
> 如果有很多 read 需要默认回车
```bash
#!/bin/bash
defaultValue1="默认值1"
defaultValue2="默认值2"
echo "请输入内容1"
read userInput1
userInput1=${userInput1:-$defaultValue1}
echo "请输入内容2"
read userInput2
userInput2=${userInput2:-$defaultValue2}
echo "你输入的内容1是$userInput1"
echo "你输入的内容2是$userInput2"
```
执行脚本
```bash
bash shell.sh <<< $'\n\n'
```
## 如何模拟按钮选择
[Shell文件](https://gitee.com/offends/Linux/blob/main/File/Shell/button.sh)
下载 Shell 示例
```bash
wget https://gitee.com/offends/Linux/raw/main/File/Shell/button.sh
```
## Nginx证书签发
[Shell文件](https://gitee.com/offends/Linux/blob/main/File/Shell/nginx-ssl.sh)
下载 Shell 示例
```bash
wget https://gitee.com/offends/Linux/raw/main/File/Shell/nginx-ssl.sh
```
## Mysql定时备份脚本
1. 创建备份文件存储目录
```bash
mkdir -p /opt/mysql/backup && cd /opt/mysql/backup
```
2. 下载脚本
```bash
wget https://gitee.com/offends/Linux/raw/main/File/Shell/mysql-backup.sh
```
修改如下内容
```bash
MYSQL_HOST=<MYSQL_HOST>
MYSQL_USER=root
MYSQL_PASS=root
```
3. 配置计划任务
```bash
crontab -e
```
添加定时任务
```bash
0 2 * * * bash /opt/mysql/backup/mysql-backup.sh
```

97
builder.sh Normal file
View File

@@ -0,0 +1,97 @@
#!/bin/bash
#############################################################################################
# 用途: 初始化文档脚本
# 作者: 丁辉
# 编写时间: 2024-07-30
#############################################################################################
# 定义函数信息
RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[32m'
YELLOW='\033[33m'
TIME="+%Y-%m-%d %H:%M:%S"
function SEND_INFO() {
info=$1
echo -e "${GREEN}$(date "$TIME") INFO: $info${NC}"
}
function SEND_WARN() {
warn=$1
echo -e "${YELLOW}$(date "$TIME") WARN: $warn${NC}"
}
function SEND_ERROR() {
error=$1
echo -e "${RED}$(date "$TIME") ERROR: $error${NC}"
}
# 整理文档
function Clean_File() {
SEND_INFO "------------ 开始清理仓库内无关文件 ------------"
SEND_INFO "------------ Git 文件清理 ------------"
rm -rf .git
rm -rf .gitignore
rm -rf .drone.yml
rm -rf ./README.md
SEND_INFO "------------ 特殊文件/目录清理 ------------"
find . -type f ! \( -name "*.md" -o -name "builder.sh" \) -exec rm {} +
SEND_INFO "------------ 开始初始化文档 ------------"
SEND_INFO "------------ README.md 文件初始化 ------------"
# 清理第一行带有 * 号文件
for i in $(find ./ -type f -name "*.md"); do
if head -n 1 ${i} | grep -q '^*'; then
rm ${i}
fi
done
# 更改剩下的文件名称
for i in $(find ./ -type f -name "README.md"); do
path=$(echo $i | awk -F'/README.md' '{print $1}')
name=$(sed -n '3p' $i | awk '{print $2}')
mv $i ${path}/${name}.md
done
}
# 初始化 MD 文件
function Init_Docs() {
SEND_INFO "------------ 初始化文档正文 ------------"
for i in $(find ./ -type f -name "*.md" | sed 's|^./||'); do
DNAME=$(echo $i | awk -F '/' '{print "Linux-"$1}')
MDNAME=$(echo $i | awk -F '/' '{print $(NF)}' | awk -F '.' '{print $1}')
sed -i "1i---\n\
title:\n\
keywords: admin-template,vue,element,后台模板\n\
cover: /img/block.png\n\
sticky:\n\
banner:\n\
type: img\n\
bgurl: /img/demo.png\n\
bannerText: \n\
author: Offends\n\
categories:\n\
toc: true\n\
single_column: true\n\
---\n" $i
sed -i "s#title:#title: $MDNAME#g" $i
sed -i "s#categories:#categories: $DNAME#g" $i
done
}
function Replace_Url() {
SEND_INFO "------------ 开始替换 Gitee 链接为 Blog 链接 ------------"
for i in $(grep -r 'https://gitee.com/offends/' . | awk -F ':' '{print $1}'); do
sed -i 's|https://gitee.com/offends/\(.*\)blob/main/\(.*\.md\)|https://blog.offends.cn/\1\2|g' $i || true
sed -i 's|\.md$|.html|g' $i || true
sed -i 's|\.md)$|.html)|g' $i || true
done
}
function All() {
SEND_INFO "开始构建......"
Clean_File
Init_Docs
Replace_Url
SEND_INFO "构建完成"
}
All

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 ${逻辑设备}
```

View File

@@ -0,0 +1,270 @@
> 本文作者:丁辉
# MYSQL字符集
[Unicode 标准](https://home.unicode.org/)
## 常用基础 sql 命令
> 以 "utf8mb4" 字符集作为示例
- 查看当前 MYSQL 支持的字符集
```sql
show collation;
```
> 过滤 "utf8mb4" 字符集
>
> ```sql
> SHOW COLLATION LIKE 'utf8mb4%';
> ```
- 查看 "数据库" 或 "表" 字符集
```sql
show create database <库名>;
```
```sql
show create table <表名>;
```
- 创建时指定字符集
- 创建 "数据库" 指定字符集
```sql
CREATE DATABASE <库名> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
- 创建 "表" 指定字符集
```sql
CREATE TABLE demo_table (
name VARCHAR(3)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
- 修改字符集
- 修改 "数据库" 字符集
```sql
ALTER DATABASE <库名> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
- 修改 "表" 字符集
```sql
ALTER TABLE <表名> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
## 常见的 MySQL 字符集和排序规则
| 字符集 | 排序规则 |
| :----------------: | :----------------------------------------------------------: |
| utf8mb4_general_ci | 一般排序规则,对各种语言都能工作,但不支持所有语言的精确排序。 |
| utf8mb4_bin | 二进制排序规则,区分大小写,直接按照字符编码的二进制值排序。 |
| utf8mb4_unicode_ci | Unicode排序规则更准确地排序各种语言的字符但可能会比较耗费资源。 |
# MYSQL 授权
> 以 "offends" 用户作为示例
- 查看 MYSQL 用户
```sql
select user,host from mysql.user;
```
- 创建用户
```sql
CREATE USER offends IDENTIFIED BY 'offends';
```
>创建用户时配置允许哪些主机登录
>
>```sql
>CREATE USER 'offends'@'host' IDENTIFIED BY 'offends';
>```
- 用户权限
- 查看权限
```sql
SHOW GRANTS FOR 'offends'@'%';
```
- 删除权限
```sql
REVOKE ALL PRIVILEGES ON *.* FROM 'offends'@'%';
```
- 授权用户
- 完整权限授权
```sql
GRANT ALL PRIVILEGES ON *.* TO 'offends'@'%' IDENTIFIED BY 'offends';
```
> - `GRANT`: 这个关键字表示你要给予权限。
> - `ALL PRIVILEGES`: 表示赋予用户所有权限包括SELECT、INSERT、UPDATE、DELETE等等。
> - `*.*`: 这部分表示所有数据库和所有表。第一个星号表示所有数据库,第二个星号表示所有表。
> - `TO 'offends'@'%'`: 表示授予权限给一个名为 'offends' 的用户,@'%' 表示这个用户可以从任何主机连接到数据库。如果你希望用户只能从特定主机连接,可以在这里指定该主机的 IP 地址或主机名。
> - `IDENTIFIED BY 'offends'`: 表示用户的密码是 'offends'。这是用于验证用户身份的密码。
- 普通授权
- 指定数据库授权,配置主机登录
```sql
GRANT ALL PRIVILEGES ON <需要授权库名>.* TO 'offends'@'localhost' IDENTIFIED BY 'offends';
```
- 配置普通权限
```sql
GRANT SELECT ON offends.* TO 'offends'@'%' IDENTIFIED BY 'offends';
```
> 通常情况下公司内部授予查询权限
- 信任用户委派权限管理(用户可以将权限分配给其他用户)
```sql
GRANT ALL PRIVILEGES ON *.* TO 'offends'@'%' WITH GRANT OPTION;
```
- 刷新reload权限确保当前对用户权限的更改立即生效。
```sql
FLUSH PRIVILEGES;
```
# MYSQL 常用命令
- 使用 mysqladmin 修改密码
```bash
mysqladmin -u用户名 -p旧密码 password 新密码
```
- 修改密码
> MYSQL 5.7
```sql
update mysql.user set authentication_string=password('newpassword') where user='offends';
```
> 刷新
>
> ```sql
> FLUSH PRIVILEGES;
> ```
>
>忘记密码则可以在 MYSQL 配置文件 my.cnf 内添加 `skip-grant-tables` 开启免密登录修改密码
- 修改(无法加载身份验证插件"caching_sha2_password")问题
```sql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<密码>';
```
- 修改表中数据
```sql
UPDATE <表名> SET <需要修改的字段>='值' WHERE ID='字段ID号';
```
- 查看数据库表结构
```sql
SHOW CREATE TABLE <表名>;
```
- 修改数据库表结构
```sql
alter table <表名> modify column <字段> <修改后的字段> NULL;
```
- 重置副本数
```bash
RESET REPLICA;
```
- 禁止导出gtid信息
```bash
mysqldump -uroot -p密码 库 --set-gtid-purged=off > demo.sql
```
- 清空所有GTID信息
```bash
reset slave all;
reset master;
```
# MYSQL 备份
- MYSQL 备份,禁止导出gtid信息
```sql
mysqldump -uroot -p<密码> <库> --set-gtid-purged=off > backup.sql
```
- MYSQL 全量备份
```sql
mysqldump -uroot -p<密码> --all-databases > backup.sql
```
> | 参数 | 描述 |
> | ---------------------- | ------------------------------------------------------------ |
> | `--quick` | 使用快速插入方式,适用于大型数据库,减少锁定时间 |
> | `--events` | 备份事件Event信息这包括触发器等 |
> | `--all-databases` | 备份所有数据库 |
> | `--flush-logs` | 备份时刷新 MySQL 的日志,确保备份包含完整的事务日志 |
> | `--delete-master-logs` | 备份后删除主服务器上的二进制日志,释放磁盘空间 |
> | `--single-transaction` | 在整个备份过程中使用单一事务,保证数据的一致性,适用于 InnoDB 存储引擎 |
- MYSQL 增量备份
- 检查是 log_bin 是否开启(增量备份需开启)
```sql
show variables like '%log_bin%';
```
> 配置 my.cnf 添加 `log-bin=/var/lib/mysql/backup` 开启 log_bin
- 增量备份
```bash
mysqladmin -uroot -p<密码> flush-logs
```
> 在 /var/lib/mysql/backup 下查看增量备份日志
- 恢复增量备份
```bash
mysqlbinlog /var/lib/mysql/backup/binlog.000008 | mysql -uroot -p<密码>;
```

View File

@@ -0,0 +1,54 @@
> 本文作者:丁辉
# Mysql数据库常用指令
- 创建数据库指定utf8mb4字符集
```bash
create database $database default character set utf8mb4 collate utf8mb4_unicode_ci;
```
- 修改数据库表判定是否可以为空
```bash
alter table 表名 modify column 字段 varchar(64) NULL;
```
- 查看数据库表结构
```bash
SHOW CREATE TABLE 库.表;
```
- 备份库
```bash
mysqldump -uroot -p密码 库 > demo.sql
```
- 备份表
```bash
mysqldump -uroot -p密码 库 表 > demo.sql
```
- 重置副本数
```bash
RESET REPLICA;
```
- 禁止导出gtid信息
```bash
mysqldump -uroot -p密码 库 --set-gtid-purged=off > demo.sql
```
- 清空所有GTID信息
```bash
reset slave all;
reset master;
```

View File

@@ -0,0 +1,9 @@
*
> 本文作者:丁辉
# Mysql相关文档
- [Mysql双主部署](https://gitee.com/offends/Linux/src/branch/main/%E8%B5%84%E6%BA%90%E5%AE%89%E8%A3%85/Mysql%E5%8F%8C%E4%B8%BB%E9%83%A8%E7%BD%B2.md)

View File

@@ -0,0 +1,107 @@
> 本文作者:丁辉
# Linux镜像下载
> 进入网站后有的小伙伴见到一大堆目录蒙了,不知道如何选择。还好我贴心的写上了示例
## 官方提供的下载网址如下
### Centos
[官方下载地址主页](https://www.centos.org/download/)
[官方阿里源下载地址主页](http://mirror.centos.org/)
X86访问 `http://isoredirect.centos.org/centos/7.9.2009/isos/x86_64/`
Arm访问 `http://mirror.centos.org/altarch/7.9.2009/isos/`
### Ubuntu
[官方主页](https://ubuntu.com/download)
[官方国内源](https://cn.ubuntu.com/)
## 国内下载网址
[阿里云镜像站主页](https://developer.aliyun.com/mirror/)
[阿里云镜像站Centos主页](https://developer.aliyun.com/mirror/centos) (主页同时也提供系统安装源可查看文档替换)
X86访问 `http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/`
Arm的镜像在阿里云镜像主页点击OS镜像查找下载
[阿里云镜像站Ubuntu主页](https://developer.aliyun.com/mirror/ubuntu/) (主页同时也提供系统安装源可查看文档替换)
X86访问 `http://mirrors.aliyun.com/ubuntu-releases/`
Arm的镜像在阿里云镜像主页点击OS镜像查找下载
## Windows系统下载
[List of files by Microsoft](https://files.rg-adguard.net/category)
## UTM提供的下载地址
[镜像下载地址](https://mac.getutm.app/gallery/)
## MSDN,我告诉你
[镜像下载地址](https://msdn.itellyou.cn/)
## 各版本区别
### CentOS Linux 与CentOS Stream 的区别
CentOS Linux是Red Hat Enterprise LinuxRHEL的重建版本。因此它是RHEL的下游。CentOS Linux 发行版号反映了它们所基于的 RHEL 版本的日期。
### CentOS 7 版本之间的区别
1. **DVD**
- CentOS 7 和 CentOS 8 都提供了 DVD 版本,通常称为 "DVD ISO"。这些 DVD 版本包含了大量的软件包,可以在离线状态下安装 CentOS而不需要依赖于互联网连接。DVD 版本通常用于以下情况:
2. **Everything**
- 这是最大的 CentOS 安装镜像,包含了 CentOS 提供的几乎所有软件包,以及额外的软件包,如开发工具、库文件和桌面环境等。
- "Everything" 版本通常用于需要大量软件包和功能的用途,比如服务器环境或者需要在单个镜像中包含各种开发工具的场景。
3. **Minimal**
- "Minimal" 版本相对较小,只包含了操作系统的核心组件和最少的软件包。这个版本的目标是提供一个最小的安装镜像,以便用户可以根据需要选择和安装额外的软件包。
- "Minimal" 版本通常用于构建自定义服务器环境,因为它提供了更大的灵活性,用户可以根据需要选择要安装的软件包。
4. **NetInstall**
- "NetInstall" 版本是一个非常小的镜像,它通常只包含引导加载程序和安装程序。在安装过程中,系统将从互联网下载所需的软件包并安装它们。
- "NetInstall" 版本适用于具有稳定互联网连接的情况,因为它依赖于在线软件包存储库。这个版本的好处是安装时可以获取最新的软件包,而不需要等待大型镜像的更新。
### Centos7.9 2009 与 2207 的区别
2207 ISO 仅适用于 xtra 硬件支持或时区。在 2020 年 9 月发布较旧的 2009 时不受支持。
# Docker构建Debian系统
[官方网址](https://docker.debian.net/)
**介绍**
- `debian:bullseye`代表Debian 11代号为Bullseye版本。这是Debian的最新稳定版本截至2021年9月
- `debian:bookworm`代表Debian 12代号为Bookworm版本。这是Debian的下一个预计发布的稳定版本。
- `debian:buster`代表Debian 10代号为Buster版本。这是Debian的上一个稳定版本。
- `debian:oldoldstable`代表Debian的非常旧的稳定版本。这是过去的老版本已经不再得到官方支持。
- `debian:oldstable`代表Debian的旧的稳定版本。这是上一个稳定版本仍然得到有限的官方支持。
- `debian:sid`代表Debian的不稳定版本。这个版本是开发中的版本可能包含最新的软件包和实验性功能但也可能存在不稳定性和不完全测试的问题。
- `debian:stable`代表Debian的当前稳定版本。这是官方推荐的用于生产环境的版本具有稳定性和广泛的软件包支持。
- `debian:testing`代表Debian的测试版本。这个版本是下一个稳定版本的候选版本用于进行测试和准备工作。它包含较新的软件包但可能不够稳定。
- `debian:trixie`这个标签可能是一个虚构的版本不是Debian官方提供的标签。
- `debian:unstable`代表Debian的不稳定版本也称为"sid"。与`debian:sid`标签相同,这个版本包含最新的软件包和实验性功能,但可能存在不稳定性和不完全测试的问题。

View File

@@ -0,0 +1,203 @@
> 本文作者:丁辉
>
# 开始安装系统
> 绝对保姆级攻略,你要告诉我这样你再不会弄,我一个飞腿~欻~
1. 选择 Install Ubuntu Server
<img src="https://minio.offends.cn:9000/offends/images/image-20230831145859307.png" style="zoom:25%;" />
> 显示这个可以等待一会就好了
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831203046055.png" style="zoom:25%;" />
2. 选择语言回车(这里我们选择默认)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831145955098.png" style="zoom:25%;" />
<img src="https://minio.offends.cn:9000/offends/images/image-20230831150014531.png" style="zoom:25%;" />
3. 这里可以选择安装系统的类型
<img src="https://minio.offends.cn:9000/offends/images/image-20230831150044890.png" style="zoom:25%;" />
4. 配置网络这里可以直接选择 Done 先使用默认分配的网络
<img src="https://minio.offends.cn:9000/offends/images/image-20230831161723916.png" style="zoom:25%;" />
> 我这里就配置静态IP地址喽
>
> 步骤如下:
>
> 1. 安上键到第一块网卡上回车,选择编辑 IPv4信息
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831163200011.png" style="zoom:25%;" />
>
> 2. 选择 Manual 手动配置
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831163703830.png" style="zoom:25%;" />
>
> 3. 填写新IP信息
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831203906566.png" style="zoom:25%;" />
>
> **Subnet:** 这是子网掩码,你的子网掩码应该是 `192.168.1.0/24` 这种格式。
>
> **Address:** 这是你要为网络接口分配的 IPv4 地址它由四个数字组成例如192.168.1.100。
>
> **Gateway:** 这是默认网关的 IPv4 地址。默认网关是你的计算机将数据包发送到其他网络时的出口点。
>
> **Name servers:** 这是 DNS 服务器的 IPv4 地址,用于解析域名到 IP 地址。你可以提供一个或多个 DNS 服务器的地址,用逗号分隔。
>
> **Search domains:** 这是搜索域的列表,用于在没有完全限定域名的情况下解析主机名。多个域名可以用逗号分隔。
>
>
>
> 4. 保存信息
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831181236660.png" style="zoom:25%;" />
5. 配置代理,默认即可
<img src="https://minio.offends.cn:9000/offends/images/image-20230831182016257.png" style="zoom:25%;" />
6. 配置系统镜像源
> 当前版本默认是:`http://cn.ports.ubuntu.com/ubuntu-ports`
>
> 更换为阿里云的:`https://mirrors.aliyun.com/ubuntu-ports/`
>
> 更换完可以按 `Try again now` 重新检查(正常直接略过也没啥问题)或你可以直接使用默认的
<img src="https://minio.offends.cn:9000/offends/images/image-20230831183328211.png" style="zoom:25%;" />
7. 提示正在检查,直接选择 Continue 跳过
<img src="https://minio.offends.cn:9000/offends/images/image-20230831183435765.png" style="zoom:25%;" />
8. 配置存储磁盘
<img src="https://minio.offends.cn:9000/offends/images/image-20230831183935988.png" style="zoom:25%;" />
9. 编辑 / 分区使用所有容量(不改的话 / 会很小)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831185035744.png" style="zoom:25%;" />
配置 Size 为空则会使用剩余全部空间(后面发现不行了,那就按照剩余存储填一下,反正左侧提示最大可用值)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831185134687.png" style="zoom:25%;" />
保存检查空间大小
<img src="https://minio.offends.cn:9000/offends/images/image-20230831185419003.png" style="zoom:25%;" />
提示警告,选择继续
<img src="https://minio.offends.cn:9000/offends/images/image-20230831185530548.png" style="zoom:25%;" />
> 添加磁盘
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831184702593.png" style="zoom:25%;" />
>
> 填入大小,也可以选择创建一个卷
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831185014156.png" style="zoom:25%;" />
10. 填写系统信息
<img src="https://minio.offends.cn:9000/offends/images/image-20230831204348270.png" style="zoom:25%;" />
11. 选择跳过系统升级
<img src="https://minio.offends.cn:9000/offends/images/image-20230831204736733.png" style="zoom:25%;" />
12. 配置安装远程访问(直接跳过)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831204945704.png" style="zoom:25%;" />
13. 第三方软件安装(直接跳过)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831225632113.png" style="zoom:25%;" />
> 有图的人请给我一个谢谢, mdan丢了......
14. 开始安装(可选择 Cancel update and reboot 跳过更新并重新启动)
<img src="https://minio.offends.cn:9000/offends/images/image-20230831205241014.png" style="zoom:25%;" />
15. 安装完成选择重启
<img src="https://minio.offends.cn:9000/offends/images/image-20230831205357176.png" style="zoom:25%;" />
16. 重启后会到这个页面,这时我们需要卸载光盘,点击右上角那一栏圆圆的图表
<img src="https://minio.offends.cn:9000/offends/images/image-20230831210526461.png" style="zoom:25%;" />
选择弹出
<img src="https://minio.offends.cn:9000/offends/images/image-20230831210638885.png" style="zoom:25%;" />
17. 点击左上角那一栏三角形图表重启主机,提示选择确定
<img src="https://minio.offends.cn:9000/offends/images/image-20230831210855628.png" style="zoom:50%;" />
> 显示这个可以等待一会就好了
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831203046055.png" style="zoom:25%;" />
18. 输入刚才配置的账号密码,进入系统
<img src="https://minio.offends.cn:9000/offends/images/image-20230831211004490.png" style="zoom: 25%;" />
# 配置Root用户
1. 配置 Root 用户密码
```bash
sudo passwd root
```
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221007515.png" style="zoom:67%;" />
2. 开启 SSH 登录
`sudo vi /etc/ssh/sshd_config` 修改这俩参数 `PermitRootLogin` `PasswordAuthentication`
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221055822.png" style="zoom: 25%;" />
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221120838.png" style="zoom: 25%;" />
3. 重启 SSH 服务
```bash
sudo service ssh restart
```
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221154933.png" />
# 使用工具连接虚拟主机
1. 关闭虚拟机,点击右上角设置
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221455831.png" style="zoom: 33%;" />
2. 点击网络,配置网络模式为模拟 VLAN
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221509466.png" style="zoom: 50%;" />
3. 点击端口转发填写虚拟机IP地址以及需要对外转发的端口这里填写 22 ,对外端口则是 10022
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221617184.png" style="zoom: 33%;" />
4. MAC启动台搜索终端打开终端登录
```bash
ssh -p 10022 root@localhost
```
<img src="https://minio.offends.cn:9000/offends/images/image-20230831221806400.png" />

View File

@@ -0,0 +1,131 @@
> 本文作者:丁辉
# MAC-M1安装UTM软件
[MAC版下载地址](https://mac.getutm.app/gallery/)
1. 点击右上角的`DOWNLOAD`按钮下载软件
<img src="https://minio.offends.cn:9000/offends/images/image-20230829150206275.png" style="zoom: 25%;" />
2. 下载完成后,点击文件夹找到下载文件开始安装
<img src="https://minio.offends.cn:9000/offends/images/image-20230829150126669.png" style="zoom: 50%;" />
3. 打开安装程序后,按照提示按住鼠标左键点击`UTM`图标向右拖拽到安装目录下
<img src="https://minio.offends.cn:9000/offends/images/image-20230829145631786.png" style="zoom: 33%;" />
4. 安装完成后在MAC启动台里面找到`UTM`软件,单击打开软件。
出现安全提示,点击 "打开"
<img src="https://minio.offends.cn:9000/offends/images/image-20230829145657576.png" style="zoom: 50%;" />
5. 看到官方又在画大饼,直接下一步
<img src="https://minio.offends.cn:9000/offends/images/image-20230829145717522.png" style="zoom:33%;" />
6. 成功进入软件页面
<img src="https://minio.offends.cn:9000/offends/images/image-20230829152018450.png" style="zoom: 25%;" />
作为完美主义者,当然要右键:推出"UTM" 驱动啦
<img src="https://minio.offends.cn:9000/offends/images/image-20230829150900777.png" />
# 准备系统镜像
> 可以看到在官网我们可以选择很多系统镜像,本次我们拿 Ubuntu 系统镜像举例
1. 下滑找到 Ubuntu 20.04 点击
<img src="https://minio.offends.cn:9000/offends/images/image-20230831141032072.png" style="zoom: 25%;" />
2. 点击 Guide
<img src="https://minio.offends.cn:9000/offends/images/image-20230831141048266.png" style="zoom:25%;" />
3. 找到 Downloads 这一行选择自己需要下载的系统架构,我这里选择 Ubuntu Server for ARM
<img src="https://minio.offends.cn:9000/offends/images/image-20230831141129526.png" style="zoom:25%;" />
4. 第一次进入这里有提示的话,可以点击 Accept all and visit site
<img src="https://minio.offends.cn:9000/offends/images/image-20230829163047581.png" style="zoom:25%;" />
下载
> 1. **Ubuntu 22.04.3 LTS**
> - 这是 Ubuntu 22.04 的第三个点版本,其中 LTS 表示“长期支持”Long Term Support
> - 长期支持版本通常会得到长达 5 年的安全更新和维护,对于需要稳定性和持久性的服务器和生产环境来说是一个很好的选择。
> - 这个版本的主要焦点是提供稳定性、安全性和兼容性,适合企业和大型部署。
> 2. **Ubuntu 23.04**
> - 这是 Ubuntu 23.04 的标准版本,不包含长期支持。
> - 标准版本通常会在发布后的 9 个月内获得更新和支持。它们可能包含更多的新功能和改进,但相对于 LTS 版本来说,安全更新和维护时间较短。
> - 这个版本的主要特点可能是引入新的功能、技术和改进,适合对最新功能有兴趣的用户。
>
> 选择使用哪个版本取决于你的需求。如果你在寻找一个稳定、经过充分测试的版本,特别是在服务器或生产环境中使用,通常建议选择 LTS 版本(在这种情况下是 Ubuntu 22.04.3 LTS。如果你对新功能和改进更感兴趣可以选择标准版本在这种情况下是 Ubuntu 23.04)。
5. 我选择下载 LTS 版本
<img src="https://minio.offends.cn:9000/offends/images/image-20230831141147474.png" style="zoom:25%;" />
# 创建虚拟机
打开 UTM 软件,选择:
1. 点击新建一个虚拟机
2. 选择虚拟化
<img src="https://minio.offends.cn:9000/offends/images/image-20230831141258499.png" style="zoom:25%;" />
3. 选择 Linux
<img src="https://minio.offends.cn:9000/offends/images/image-20230831143724024.png" style="zoom:25%;" />
4. 点击:浏览 选择刚才下载的 ISO 镜像
<img src="https://minio.offends.cn:9000/offends/images/image-20230831144225028.png" style="zoom:25%;" />
5. 配置虚拟机内存和CPU
<img src="https://minio.offends.cn:9000/offends/images/image-20230831144447286.png" style="zoom:25%;" />
6. 配置存储大小
<img src="https://minio.offends.cn:9000/offends/images/image-20230831144844318.png" style="zoom:25%;" />
7. 点击下一步
<img src="https://minio.offends.cn:9000/offends/images/image-20230831145032838.png" style="zoom:25%;" />
8. 点击保存
<img src="https://minio.offends.cn:9000/offends/images/image-20230831145120531.png" style="zoom:25%;" />
创建完成之后是这个样子的
<img src="https://minio.offends.cn:9000/offends/images/image-20230831145335709.png" style="zoom:25%;" />

View File

@@ -0,0 +1,130 @@
> 本文作者:丁辉
>
# MAC使用VMwareFusion创建虚拟机
> 绝对保姆级攻略,你要告诉我这样你再不会弄,我一个飞腿~欻~
1. 点击新建
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224634401.png" style="zoom:25%;" />
2. 选择从光盘或映像中安装点击继续
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224650293.png" style="zoom: 33%;" />
3. 这里可以拖拽虚拟机镜像文件到中间,点击继续
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224714265.png" style="zoom: 33%;" />
4. 点击完成
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224734193.png" style="zoom: 33%;" />
5. 提示选择存储位置选择好后点击存储
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224803860.png" style="zoom: 50%;" />
6. 关闭虚拟机点击上栏设置
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224851356.png" style="zoom:25%;" />
7. 配置虚拟机基础参数
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224905868.png" style="zoom: 33%;" />
8. 配置内存和CPU
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224950894.png" style="zoom: 33%;" />
9. 配置磁盘大小
<img src="https://minio.offends.cn:9000/offends/images/image-20230831224937452.png" style="zoom: 50%;" />
# 安装虚拟机
[请看这篇文档](https://blog.offends.cn/blog/Kubernetes%E5%AD%A6%E4%B9%A0%E8%AE%B0%E5%BD%95/MAC-M1%E4%BD%BF%E7%94%A8UTM%E5%88%9B%E5%BB%BA%E8%99%9A%E6%8B%9F%E6%9C%BA/) ,步骤是一样的,就不重复写了
> 安装完成后,重启遇到这个直接回车就好
>
> 不想遇到这个直接卸载光盘就不会出现了
>
> <img src="https://minio.offends.cn:9000/offends/images/image-20230831234905184.png" style="zoom: 25%;" />
# 不通网段的情况下,宿主机如何和虚拟机通信?
> 1. **"与我的Mac共享"Share with my Mac**
> - 这个模式使虚拟机和主机 Mac 共享同一个网络。虚拟机会获得与主机 Mac 同一网络子网的 IP 地址,通常是在 NAT 模式下。这意味着虚拟机和主机 Mac 能够相互通信,但虚拟机无法与局域网内的其他设备直接通信。
> - 适用于需要虚拟机与主机 Mac 共享网络连接的情况,例如,需要使用主机 Mac 的网络连接来浏览互联网的情况。
> 2. **"自动检测"Bridged - Autodetect**
> - 这个模式尝试自动检测可用的网络连接并将虚拟机连接到其中一个网络。通常它会尝试连接到物理网络接口例如Wi-Fi 或以太网),以便虚拟机与局域网内的其他设备进行通信。
> - 适用于需要虚拟机与局域网内其他设备进行通信的情况,例如,虚拟机需要作为一个独立的计算机出现在网络中。
> 3. **"Wi-Fi"**
> - 这个模式将虚拟机连接到主机 Mac 的 Wi-Fi 接口,使虚拟机可以访问 Wi-Fi 网络。虚拟机将获得与 Wi-Fi 网络相同的 IP 地址范围,并可以与 Wi-Fi 网络上的其他设备通信。
> - 适用于需要虚拟机连接到 Wi-Fi 网络的情况,例如,测试或开发需要使用无线连接的应用程序。
>
> 4. **"仅供我的Mac专用"Host-Only**
> - 这个模式创建了一个仅供虚拟机和主机 Mac 使用的专用网络。虚拟机之间和虚拟机与主机 Mac 可以互相通信,但虚拟机无法直接访问外部网络。
> - 适用于需要虚拟机之间通信,但不需要与外部网络通信的情况,例如,搭建内部测试环境。
> 5. **"自定义vmnet网络"**
> - 这个模式涉及到 VMware Fusion 的自定义网络配置通常需要手动设置。您可以创建和配置自定义的虚拟网络如vmnet3并为虚拟机分配到该网络。这使得您可以精确地控制虚拟机与其他网络和主机 Mac 之间的连接方式。
> - 适用于需要高度定制化的网络配置,例如,特定的测试环境或安全隔离网络。
<img src="https://minio.offends.cn:9000/offends/images/image-20230901150547961.png" style="zoom: 25%;" />
## 配置自定义vmnet网络
1. 首先我们进入 VMware Fusion 的配置界面
> 快捷键是 Command+,
>
> 或者点击左上角设置
<img src="https://minio.offends.cn:9000/offends/images/image-20230901103316741.png" style="zoom: 50%;" />
2. 点击网络
> 我们需要先把左下角的🔒打开他会让你输入MAC密码
<img src="https://minio.offends.cn:9000/offends/images/image-20230901111017948.png" style="zoom: 33%;" />
3. 配置网络信息
<img src="https://minio.offends.cn:9000/offends/images/image-20230901151127156.png" style="zoom: 33%;" />
4. 添加端口转发
<img src="https://minio.offends.cn:9000/offends/images/image-20230901151252729.png" style="zoom:50%;" />
5. 信息填好之后点击应用保存
<img src="https://minio.offends.cn:9000/offends/images/image-20230901151311948.png" style="zoom: 33%;" />
这时虚拟机内部配置好IP地址为 `192.168.100.10` 在宿主机连接 `ssh -p 10022 root@localhost` 则可以 SSH 连接虚拟机
## 查看网卡信息
查看网段信息
```bash
cat /Library/Preferences/VMware\ Fusion/networking
```
查看网关信息
```bash
cat /Library/Preferences/VMware\ Fusion/vmnet3/nat.conf
```
查看地址池信息
```bash
cat /Library/Preferences/VMware\ Fusion/vmnet3/dhcpd.conf
```

View File

@@ -0,0 +1,128 @@
> 本文作者:丁辉
# PorxmoxVE安装文档
[官网](https://www.proxmox.com/en/) [ISO](https://enterprise.proxmox.com/iso/)
## 准备工作
1. 登录官网下载镜像
<img src="https://minio.offends.cn:9000/offends/images/image-20240720194208265.png" style="zoom: 50%;" />
2. 制作安装U盘
<img src="https://minio.offends.cn:9000/offends/images/image-20240722094048963.png" style="zoom: 50%;" />
## 开始安装
1. 上下键选择桌面版(Graphical)回车
<img src="https://minio.offends.cn:9000/offends/images/image-20240720185451758.png" style="zoom: 50%;" />
2. 点击我同意
<img src="https://minio.offends.cn:9000/offends/images/image-20240720185723322.png" style="zoom: 50%;" />
3. 选择系统安装磁盘位置,点击我同意
<img src="https://minio.offends.cn:9000/offends/images/image-20240720185814927.png" style="zoom: 50%;" />
4. 选择地区 China时区 Asia/Shanghai键盘布局 U.S.English点击我同意
<img src="https://minio.offends.cn:9000/offends/images/image-20240720185921809.png" style="zoom: 50%;" />
5. 配置平台登陆密码,填写邮箱,点击我同意
<img src="https://minio.offends.cn:9000/offends/images/image-20240720190045769.png" style="zoom: 50%;" />
6. 选择网卡配置平台访问IP和网关地址点击我同意
<img src="https://minio.offends.cn:9000/offends/images/image-20240720190319389.png" style="zoom: 50%;" />
7. 点击安装
<img src="https://minio.offends.cn:9000/offends/images/image-20240720190345393.png" style="zoom: 50%;" />
8. 等待安装完成后重启即可(注意安装完重启时拔掉U盘)
<img src="https://minio.offends.cn:9000/offends/images/image-20240720190410286.png" style="zoom: 50%;" />
9. 出现这个画面则代表安装成功
<img src="https://minio.offends.cn:9000/offends/images/image-20240720190733844.png" style="zoom: 50%;" />
11. 选择语言,填写用户名密码后登录
<img src="https://minio.offends.cn:9000/offends/images/image-20240720191019973.png" style="zoom: 50%;" />
12. 忽略提示点击OK
<img src="https://minio.offends.cn:9000/offends/images/image-20240720191043872.png" style="zoom: 50%;" />
13. 配置国内源
1. 备份源文件
```bash
cp /etc/apt/sources.list /etc/apt/sources.list.bak
cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.bak
```
2. 更换 Proxmox VE 的 GPG 公钥
```bash
mv /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg.bak
wget https://mirrors.ustc.edu.cn/proxmox/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg
```
3. 更换 Proxmox 软件源
```bash
echo "#deb https://enterprise.proxmox.com/debian/pve bullseye pve-enterprise" > /etc/apt/sources.list.d/pve-enterprise.list
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/pve bullseye pve-no-subscription" > /etc/apt/sources.list.d/pve-no-subscription.list
```
4. 更换 Debian 源
```bash
sed -i "s#ftp.debian.org/debian#mirrors.aliyun.com/debian#g" /etc/apt/sources.list
sed -i "s#security.debian.org#mirrors.aliyun.com/debian-security#g" /etc/apt/sources.list
```
5. 更换 CEPH 源
```bash
echo "deb https://mirrors.ustc.edu.cn/proxmox/debian/ceph-quincy bookworm no-subscription" > /etc/apt/sources.list.d/ceph.list
sed -i.bak "s#http://download.proxmox.com/debian#https://mirrors.ustc.edu.cn/proxmox/debian#g" /usr/share/perl5/PVE/CLI/pveceph.pm
```
6. 更换 LXC 源(根据自身情况判断是否更换!!!)
```bash
sed -i.bak "s#http://download.proxmox.com/images#https://mirrors.ustc.edu.cn/proxmox/images#g" /usr/share/perl5/PVE/APLInfo.pm
wget -O /var/lib/pve-manager/apl-info/mirrors.ustc.edu.cn https://mirrors.ustc.edu.cn/proxmox/images/aplinfo-pve-7.dat
systemctl restart pvedaemon
```
7. 更新
```bash
apt update && apt upgrade -y
```
<img src="https://minio.offends.cn:9000/offends/images/image-20240720201434354.png" style="zoom: 50%;" />
14. 删除订阅弹窗(非必要步骤!!!)
```bash
sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service
```
> 执行完成后浏览器Ctrl+F5强制刷新缓存。

View File

@@ -0,0 +1,5 @@
> 本文作者:丁辉
# 制作U盘系统启动盘
[UltraISO工具官网](https://www.ultraiso.net/)

View File

@@ -0,0 +1,148 @@
> 本文作者:丁辉
# 服务器安装ESXi
## 安装Rufus制作U盘启动
[官方文档](https://rufus.ie/zh/) [下载地址](https://rufus.ie/downloads/)
Rufus 是一款格式化和创建 USB 启动盘的辅助工具。
本软件适用于以下场景:
- 需要将可引导 ISO (Windows、Linux、UEFI 等) 刻录到 USB 安装媒介的情况
- 需要处理未安装操作系统的设备的情况
- 需要在 DOS 环境下刷写 BIOS 或其他固件的情况
- 需要运行低级工具的情况
下载后即开即用,无需安装。
## 下载 VMware ESXi 镜像
[VMware ESXi下载地址](https://www.vmware.com/cn/products/esxi-and-esx.html)
### 下载最新版
1. 进入网页后点击 `下载HYPERVISOR`
<img src="https://minio.offends.cn:9000/offends/images/image-20230909014031395.png" style="zoom: 25%;" />
2. 点击 `License & Download` 后点击 `login` 如果没有登录则需要注册账号
<img src="https://minio.offends.cn:9000/offends/images/image-20230909014201808.png" style="zoom: 25%;" />
3. 登录后回到此页面,下载 `VMware vSphere Hypervisor (ESXi ISO) image`
> 如果没有注册试用权限,回到此页面还得点击注册(就是填一下信息同意试用)
<img src="https://minio.offends.cn:9000/offends/images/image-20230909014629233.png" style="zoom: 25%;" />
### 选择版本下载
[产品主页](https://customerconnect.vmware.com/cn/downloads/#all_products)
1. 点击 `VMware vSphere Hypervisor (ESXi)` 的查看下载组件
<img src="https://minio.offends.cn:9000/offends/images/image-20230909015926677.png" style="zoom: 25%;" />
2. 选择版本点击下载
<img src="https://minio.offends.cn:9000/offends/images/image-20230909015954169.png" style="zoom: 25%;" />
## 安装系统
> 因为安装简单,大部分都是按回车或 F11 同意的过程,所以我们这里只列举需要手动配置或选择的地方
>
> 当前安装版本为 `6.7 ` ,但是经过详细测试 `8.0` 安装过程基本无异,所以我就不换截图了哈(绝对不是因为懒)
1. 进入系统引导
> 正在加载文件,等待开始安装
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000207987.png" style="zoom: 25%;" />
2. 按 回车
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000331776.png" style="zoom: 25%;" />
3. 按 F11
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000339635.png" style="zoom: 25%;" />
4. 选择系统安装在哪个存储盘上
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000359441.png" style="zoom: 25%;" />
5. 选择默认语言
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000405761.png" style="zoom: 25%;" />
6. 设置系统密码
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000422443.png" style="zoom: 25%;" />
7. 按 回车 重启服务器
> 提示在重启前拔出U盘
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000626903.png" style="zoom: 25%;" />
8. 系统安装成功
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000848003.png" style="zoom: 25%;" />
## 手动配置IP
1. 按 F2 输入密码进入设置
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000900096.png" style="zoom: 25%;" />
2. 选择网络配置
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000927309.png" style="zoom: 25%;" />
3. 选择 IPv4 配置
<img src="https://minio.offends.cn:9000/offends/images/image-20230909000937259.png" style="zoom: 25%;" />
4. 使用空格键选中 static编辑网络信息
<img src="https://minio.offends.cn:9000/offends/images/image-20230909001006806.png" style="zoom: 25%;" />
回车后看到信息已改变
<img src="https://minio.offends.cn:9000/offends/images/image-20230909001019876.png" style="zoom: 25%;" />
5. 按下ESC 退出,提示是否保存,点击 Y 键保存
<img src="https://minio.offends.cn:9000/offends/images/image-20230909001028491.png" style="zoom: 25%;" />
6. 保存后回到此页面,退出设置,回到主页面
<img src="https://minio.offends.cn:9000/offends/images/image-20230909001045215.png" style="zoom: 25%;" />
操作完成此时访问当前IP `192.168.1.10` 即可进入系统 Web 页面
<img src="https://minio.offends.cn:9000/offends/images/image-20230909001053836.png" style="zoom: 25%;" />
## 密钥
> 7的不想找哈哈
VMware vSphere ESXi 6
```bash
0A65P-00HD0-3Z5M1-M097M-22P7H
```
VMware vSphere ESXi 8.0
```bash
4V492-44210-48830-931GK-2PRJ4
```
分配许可证
<img src="https://minio.offends.cn:9000/offends/images/image-20230909020536868.png" style="zoom: 25%;" />
> 不得不说这新版真帅啊

View File

@@ -0,0 +1,457 @@
> 本文作者:丁辉
# KVM虚拟化
> 文档真难找!!可恶
[官方文档](https://www.linux-kvm.org/page/HOWTO)
[官网导航页](https://www.linux-kvm.org/page/Category:Docs)
[内核要求](https://www.linux-kvm.org/page/Choose_the_right_kvm_%26_kernel_version)
[Ubuntu部署文档](https://www.linux-kvm.org/page/RunningKVM)
[VNC链接工具RealVNC下载](https://www.realvnc.com/en/connect/download/vnc/)
## 开始部署KVM
### 环境准备
1. 关闭 SELINUX
```bash
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
```
2. 关闭防火墙
```bash
systemctl stop firewalld
systemctl disable firewalld
```
3. 查看CPU是否支持硬件虚拟化
- vmx Intel VT-x
- svm AMD AMD-v
```bash
egrep -i 'vmx|svm|lm' /proc/cpuinfo
```
4. 检查 KVM 模块当前是否加载
```bash
lsmod | grep kvm
```
5. 加载模块
```bash
echo "kvm" >> /etc/modules-load.d/kvm.conf
modprobe kvm
```
6. 加载适当的模块
```bash
modprobe kvm_intel # Intel processors
modprobe kvm_amd # AMD processors
```
### 开始安装
- Centos安装
1. 安装KVM
```
yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install virt-manager -y
```
2. 启动
```bash
systemctl enable libvirtd && systemctl start libvirtd
```
- Ubuntu安装
1. 安装KVM
```bash
apt-get install gcc libsdl1.2-dev zlib1g-dev libasound2-dev linux-kernel-headers pkg-config libgnutls-dev libpci-dev
```
2. 启动
```bash
systemctl enable libvirtd && systemctl start libvirtd
```
### 网卡配置
1. 编辑默认文件
```bash
vi /etc/libvirt/qemu/networks/default.xml
```
内容如下
```xml
<network>
<name>default</name>
<uuid>1113ac18-e430-4940-a412-6e838c42efbc</uuid> #不是必要的可以注释
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:c1:cd:3e'/> #不是必要的可以注释
<ip address='192.168.100.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.100.2' end='192.168.100.254'/>
</dhcp>
</ip>
</network>
```
2. 重载配置
```bash
virsh net-define /etc/libvirt/qemu/networks/default.xml
```
3. 重启网络
```bash
virsh net-destroy default && virsh net-start default
```
## 启动 Windows 虚拟机
1. 创建一个 qcow2 格式的虚拟磁盘文件
```bash
qemu-img create -f qcow2 /var/lib/libvirt/images/windows.qcow2 50G
```
2. 拷贝 ISO 镜像文件到 images 下
```bash
mv *.iso /var/lib/libvirt/images/windows.iso
```
3. 启动 KVM 虚拟机
```bash
virt-install \
--name=windows \
--ram=4096 \
--vcpus=2 \
--os-type=windows \
--os-variant=win10 \
--disk path=/var/lib/libvirt/images/windows.qcow2,size=50 \
--cdrom=/var/lib/libvirt/images/windows.iso \
--network bridge=virbr0 \
--graphics vnc,listen=0.0.0.0,port=5901 \
--noautoconsole
```
## 启动 Linux 虚拟机
> 查看KVM支持的操作系统变种和类型
>
> ```bash
> osinfo-query os | grep CentOS
> ```
1. 创建一个 qcow2 格式的虚拟磁盘文件
```bash
qemu-img create -f qcow2 /var/lib/libvirt/images/centos.qcow2 50G
```
2. 拷贝 ISO 镜像文件到 images 下
```bash
mv *.iso /var/lib/libvirt/images/centos.iso
```
3. 启动 KVM 虚拟机
```bash
virt-install \
--name=centos \
--ram=4096 \
--vcpus=2 \
--os-type=centos7.0 \
--os-variant=centos7.0 \
--disk path=/var/lib/libvirt/images/centos.qcow2,size=50 \
--cdrom=/var/lib/libvirt/images/centos.iso \
--network bridge=virbr0 \
--graphics vnc,listen=0.0.0.0,port=5902 \
--noautoconsole
```
## 常用命令及参数解释
### 命令
- **制作虚拟机快照**
```bash
virsh snapshot-create <虚拟机名称>
```
> 自定义快照名称
>
> ```bash
> virsh snapshot-create-as <虚拟机名称> <快照名称>
> ```
>
> 查看当前虚拟机所有快照
>
> ```bash
> virsh snapshot-list <虚拟机名称>
> ```
>
> 查看当前虚拟机处于哪个快照
>
> ```bash
> virsh snapshot-current <虚拟机名称> | head -2
> ```
>
> 恢复快照
>
> ```bash
> virsh snapshot-revert <虚拟机名称> <快照名称>
> ```
>
> 删除快照
>
> ```bash
> virsh snapshot-delete <虚拟机名称> <快照名称>
> ```
- **显示有关虚拟磁盘镜像文件的信息**
```bash
qemu-img info centos.qcow2
```
- **启动虚拟机**
```bash
virsh start <虚拟机名称>
```
这个命令用于启动指定名称的虚拟机。
- **停止虚拟机**
```bash
virsh shutdown <虚拟机名称>
```
通过这个命令,你可以优雅地关闭虚拟机。也可以使用 `destroy` 选项来强制关闭虚拟机。
- **重启虚拟机**
```bash
virsh reboot <虚拟机名称>
```
这个命令用于重启虚拟机。
- **查看虚拟机列表**
```bash
virsh list --all
```
该命令列出当前主机上正在运行的虚拟机。
- **创建虚拟机**
```bash
virt-install [options]
```
使用 `virt-install` 命令创建新的虚拟机可以根据需要配置虚拟机的各种参数如名称、内存、CPU、磁盘、网络等。
- **删除虚拟机**
```bash
virsh undefine <虚拟机名称>
```
这个命令用于删除虚拟机的定义,但保留虚拟机磁盘文件。
- **克隆虚拟机**
```bash
virt-clone -o <源虚拟机名称> -n <新虚拟机名称> -f <新虚拟机磁盘路径>
```
使用这个命令可以克隆一个现有虚拟机,创建一个具有相同配置的新虚拟机。
- **查看虚拟机详细信息**
```bash
virsh dominfo <虚拟机名称>
```
这个命令提供了关于指定虚拟机的详细信息如内存、CPU使用情况等。
- **连接到虚拟机控制台**
```bash
virsh console <虚拟机名称>
```
通过这个命令可以连接到虚拟机的控制台,类似于物理终端。
- **导出虚拟机配置文件**
```bash
virsh dumpxml <虚拟机名称> > <文件名>.xml
```
这个命令可以将虚拟机的配置信息导出为XML格式以便备份或迁移虚拟机。
- **虚拟机管理工具**
```bash
virt-manager
```
这是一个虚拟机管理工具,通常拥有图形用户界面,用于创建、配置和管理虚拟机。
- **VNC 显示端口信息**
```bash
virsh vncdisplay <虚拟机名称>
```
此命令用于获取虚拟机 "windows" 的 VNC 显示端口信息。VNC 是一种用于远程访问虚拟机图形界面的协议,该命令可用于查看虚拟机的 VNC 显示端口号。
- **定义虚拟机配置**
```bash
virsh define /etc/libvirt/qemu/<虚拟机名称>.xml
```
使用此命令,您可以定义(或注册)一个名为 "windows" 的虚拟机,其配置文件位于 "/etc/libvirt/qemu/windows.xml"。这将使虚拟机配置成为 libvirt 系统中的一部分,以便后续进行管理和操作。
- **编辑虚拟机配置**
```bash
virsh edit <虚拟机名称>
```
通过执行此命令,您可以编辑虚拟机 "windows" 的配置。这将打开一个文本编辑器允许您修改虚拟机的配置参数例如虚拟硬件设备、CPU、内存等。编辑后您需要保存并退出编辑器以便应用更改。
- **挂起、恢复虚拟机**
挂起
```bash
virsh suspend <虚拟机名称>
```
恢复
```bash
virsh resume <虚拟机名称>
```
- **自动开机**
开启开机自启动
```bash
virsh autostart <虚拟机名称>
```
关闭开机自启动
```bash
virsh autostart --disable <虚拟机名称>
```
- **虚拟机镜像格式转换**
> f :源镜像格式
>
> O :目标镜像格式
- 将 img 转换 raw 格式
```bash
qemu-img convert -f qcow2 -O raw /var/lib/libvirt/images/windows.img /var/lib/libvirt/images/windows.raw
```
- 将 vmdk 转换为 qcow2
```bash
qemu-img convert -f vmdk -O qcow2 /var/lib/libvirt/images/windows.vmdk /var/lib/libvirt/images/windows.qcow2
```
- 将 qcow2 转换为 vmdk
```bash
qemu-img convert -f qcow2 -O vmdk /var/lib/libvirt/images/windows.qcow2 /var/lib/libvirt/images/windows.vmdk
```
### 参数
1. `virt-install`:这是用于创建虚拟机的命令。
2. `--name=windows`:指定虚拟机的名称为 "windows"。
3. `--ram=4096`分配给虚拟机的内存大小这里是4096 MB4 GB
4. `--vcpus=2`分配给虚拟机的虚拟CPU核心数量这里是2个。
5. `--boot=cdrom`:指定虚拟机从光盘启动。
6. `--os-type=windows`:指定虚拟机的操作系统类型为 Windows。
7. `--os-variant=win10`:指定虚拟机的操作系统变种为 Windows 10。
8. `--disk path=/var/lib/libvirt/images/windows.qcow2,size=50`定义虚拟机的磁盘配置。它使用QEMU Copy-On-Writeqcow2格式存储路径为`/var/lib/libvirt/images/windows.qcow2`并分配了50 GB的磁盘空间。
9. `--cdrom=/var/lib/libvirt/images/windows.iso`:指定虚拟机的光盘映像文件路径,用于安装操作系统或引导。
10. `--network bridge=virbr0`:配置虚拟机的网络接口,将其连接到一个虚拟网络桥接接口,名为 `virbr0`。
11. `--graphics vnc,listen=0.0.0.0,port=5901`配置虚拟机的图形输出使用VNC协议并监听所有可用网络接口0.0.0.0端口号为5901。
12. `--noautoconsole`禁止自动连接到虚拟机的控制台这意味着不会在命令行中自动打开虚拟机的控制台你需要手动连接到VNC端口5901来查看虚拟机的图形界面。
### 镜像格式
1. **Raw.raw**
- Raw格式是一种未经压缩或处理的纯二进制磁盘映像格式。
- 这是一种较为简单的格式,通常用于兼容多个虚拟化平台。
- Raw格式通常没有额外的特性如快照或压缩。
2. **CowCopy-On-Write**
- Cow格式是一种写时复制格式也称为差异磁盘映像。
- Cow格式的磁盘文件只保存虚拟机中已经发生更改的数据而不是整个虚拟硬盘。
- 这可以减小虚拟硬盘的大小,但可能会导致性能损失。
3. **Qcow.qcow**
- Qcow是QEMU的一种虚拟磁盘格式类似于Cow格式。
- 它支持写时复制技术,允许快速创建虚拟机快照。
- Qcow格式通常比Raw格式更节省磁盘空间。
4. **Qcow2.qcow2**
- Qcow2是QEMU的改进版本是一种流行的虚拟磁盘格式。
- 它支持高级特性,如快照、压缩和加密。
- Qcow2格式通常是一种高度灵活且性能良好的格式适用于多种虚拟化平台。
5. **VMDK**
- VMDKVirtual Machine Disk是VMware虚拟化软件使用的虚拟磁盘格式。
- VMDK格式有多个子格式包括单一精简、多精简和懒惰精简等以满足不同的需求。
- VMware Workstation、vSphere和其他VMware产品通常使用VMDK格式。
### 基础命令之控制网络
1. **virsh net-destroy default**:
- 这个命令用于停止名为 "default" 的虚拟网络。虚拟网络是用来连接虚拟机的网络,类似于物理网络。通过执行这个命令,您停止了名为 "default" 的虚拟网络,中断了与该网络关联的虚拟机的网络连接。
2. **virsh net-start default**:
- 这个命令用于启动名为 "default" 的虚拟网络。一旦虚拟网络被停止,您可以使用这个命令来重新启动它,使其再次可用于虚拟机。
3. **virsh net-autostart default**:
- 这个命令用于配置虚拟网络 "default" 以在系统启动时自动启动。这意味着,当系统启动时,虚拟网络 "default" 将会自动启动,而无需手动执行 `virsh net-start` 命令。这对于确保虚拟网络的可用性很有用。
4. **virsh net-undefine default**:
- 这个命令用于从 `virsh` 的配置中移除名为 "default" 的虚拟网络定义。它不仅会停止虚拟网络,还会从系统中删除虚拟网络的配置。这意味着虚拟网络 "default" 不再受 `virsh` 管理,且无法再通过 `virsh` 直接管理它。
5. **virsh net-autostart --disable virbr0**:
- 这个命令用于禁用名为 "virbr0" 的虚拟网络在系统启动时自动启动。通过执行这个命令,您阻止了 "virbr0" 虚拟网络在系统启动时自动启动,需要手动启动它(使用 `virsh net-start virbr0`)以使其可用。

View File

@@ -0,0 +1,221 @@
> 本文作者:丁辉
# Keepalived部署使用
> 介绍:当前配置完全可以在大规模生产集群中使用
| 节点 | 网关IP | VIP |
| :------: | :----------: | :----------: |
| 主网关一 | 192.168.1.11 | |
| 从网关二 | 192.168.1.12 | |
| | | 192.168.1.10 |
## 安装 keepalived
```bash
yum install -y keepalived
```
## 主节点
**编辑配置文件**
```bash
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
```
内容如下
```bash
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL # 负载均衡标识, 在局域网内应该是唯一的
}
#vrrp_script check_health {
# 检测脚本
#script "/etc/keepalived/check_health_status.sh"
# 执行间隔时间
#interval 5
#}
vrrp_instance VI_1 {
# 备用状态(当 MASTER 宕机之后根据优先级提升 BACKUP 为 MASTER )
state BACKUP
# 网卡设备名
interface eth0
# 标识虚拟路由器的ID(在局域网内应该是唯一的, 0-255)
virtual_router_id 50
# 优先级
priority 100
# MASTER与BACKUP同步检查的时间间隔
advert_int 1
# 非抢占模式
nopreempt
# 本机IP地址
unicast_src_ip 192.168.1.11
# 对端IP地址
unicast_peer {
192.168.1.12
}
authentication {
# 指定认证方式
auth_type PASS
# 指定认证所使用的密码
auth_pass 1111
}
virtual_ipaddress {
192.168.1.10/24 dev eth0
}
# 路由检测, 通过检测指定的网卡是否存在来判断服务是否正常
track_interface {
eth0
}
# 开启检测脚本
#track_script {
#check_health
#}
}
```
## 从节点
**编辑配置文件**
```bash
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
```
内容如下
```bash
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL # 负载均衡标识, 在局域网内应该是唯一的
}
#vrrp_script check_health {
# 检测脚本
#script "/etc/keepalived/check_health_status.sh"
# 执行间隔时间
#interval 5
#}
vrrp_instance VI_1 {
# 备用状态(当 MASTER 宕机之后根据优先级提升 BACKUP 为 MASTER )
state BACKUP
# 网卡设备名
interface eth0
# 标识虚拟路由器的ID(在局域网内应该是唯一的, 0-255)
virtual_router_id 50
# 优先级
priority 50
# MASTER与BACKUP同步检查的时间间隔
advert_int 1
# 非抢占模式
nopreempt
# 本机IP地址
unicast_src_ip 192.168.1.12
# 对端IP地址
unicast_peer {
192.168.1.11
}
authentication {
# 指定认证方式
auth_type PASS
# 指定认证所使用的密码
auth_pass 1111
}
virtual_ipaddress {
192.168.1.10/24 dev eth0
}
# 路由检测, 通过检测指定的网卡是否存在来判断服务是否正常
track_interface {
eth0
}
# 开启检测脚本
#track_script {
#check_health
#}
}
```
## 启动 keepalived
```bash
systemctl start keepalived
systemctl enable keepalived
systemctl status keepalived
```
## 配置健康检测
1. 编辑脚本
```bash
vi /etc/keepalived/check_health_status.sh
```
内容如下
```bash
#!/bin/bash
/usr/bin/curl -I http://localhost:10254/healthz
if [ $? -ne 0 ];then
cat /var/run/keepalived.pid | xargs kill
fi
```
2. 授权
```bash
chmod +x /etc/keepalived/check_health_status.sh
```
3. 确保服务启动后,编辑 keepalived 配置文件取消检测注释,重启后生效
```bash
systemctl restart keepalived
```
## 配置 Keepalived 自恢复
> 更改 Keepalived Systemd 配置文件, 加入如下内容, Keepalived会一直重启检测服务是否恢复正常
```bash
vi /lib/systemd/system/keepalived.service
```
```bash
[Service]
# 总是重启该服务
Restart=always
# 重启间隔时间
RestartSec=10
```
## 防火墙配置
> 开放其中一种即可
- 允许vrrp流量
```bash
iptables -A INPUT -p vrrp -j ACCEPT
```
- 允许组播流量
```bash
iptables -A INPUT -m pkttype --pkt-type multicast -j ACCEPT
```

View File

@@ -0,0 +1,250 @@
> 本文作者:丁辉
# 部署 Mysql 双主
[Mysql-Rpm文件下载](https://dev.mysql.com/downloads/repo/yum/)
## 部署
> 双节点都执行以下操作
1. 下载 Mysql Rpm 文件
```bash
yum install -y wget
wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
```
2. 安装 MySQL
```bash
yum install -y mysql80-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server --enablerepo=mysql80-community --nogpgcheck
```
3. 启动 MySQL Server
```bash
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
```
## 配置
1. 查看临时密码
```bash
grep 'temporary password' /var/log/mysqld.log
```
2. 修改临时密码并配置允许远程登录
```sql
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
USE mysql;
UPDATE user SET host = '%' WHERE user = 'root';
FLUSH PRIVILEGES;
```
### Mysql 1号主节点配置
1. 停止数据库
```bash
systemctl stop mysqld
```
备份并编辑配置文件
```bash
cp /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf
```
```bash
[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log-error=/var/log/mysqld.log
secure-file-priv=NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 服务端默认utf8编码
character-set-server=utf8mb4
# 默认存储引擎
default-storage-engine=INNODB
# 主从配置
log-bin=binlog
server-id=121
gtid-mode=on
enforce-gtid-consistency=on
log-slave-updates=on
expire_logs_days=14
# Compatible with versions before 8.0
default_authentication_plugin=mysql_native_password
skip-host-cache
skip-name-resolve
[client]
#设置客户端编码
default-character-set=utf8mb4
[mysql]
# 设置mysql客户端默认编码
default-character-set=utf8mb4
```
2. 重新启动
```bash
systemctl start mysqld
```
3. 登录数据库授权
```sql
CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
flush privileges;
SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用
```
### Mysql 2号主配置
1. 停止数据库
```bash
systemctl stop mysqld
```
备份并编辑配置文件
```bash
cp /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf
```
```bash
[mysqld]
pid-file=/var/run/mysqld/mysqld.pid
socket=/var/lib/mysql/mysql.sock
datadir=/var/lib/mysql
log-error=/var/log/mysqld.log
secure-file-priv=NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# 服务端默认utf8编码
character-set-server=utf8mb4
# 默认存储引擎
default-storage-engine=INNODB
# 主从配置
log-bin=binlog
server-id=122
gtid-mode=on
enforce-gtid-consistency=on
log-slave-updates=on
expire_logs_days=14
# Compatible with versions before 8.0
default_authentication_plugin=mysql_native_password
skip-host-cache
skip-name-resolve
[client]
#设置客户端编码
default-character-set=utf8mb4
[mysql]
# 设置mysql客户端默认编码
default-character-set=utf8mb4
```
2. 重新启动
```bash
systemctl start mysqld
```
3. 登录数据库授权
```sql
CREATE USER 'slave'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'%';
flush privileges;
SHOW MASTER STATUS; #此信息记录等会配置另外一台节点需要用
```
### Mysql 1号主节点配置
1. 开启同步
```sql
CHANGE MASTER TO
MASTER_HOST='', #IP地址
MASTER_USER='slave',
MASTER_PASSWORD='password', #密码
MASTER_PORT=3306,
MASTER_LOG_FILE='binlog.000002', #节点2 binlog 信息
MASTER_LOG_POS=821; #节点2 log_pos信息
```
2. 开启主从同步
```sql
start slave;
```
3. 查看同步状态
```sql
show slave status\G;
```
### Mysql 2号主节点配置
1. 开启同步
```sql
CHANGE MASTER TO
MASTER_HOST='', #IP地址
MASTER_USER='slave',
MASTER_PASSWORD='password', #密码
MASTER_PORT=3306,
MASTER_LOG_FILE='binlog.000002', #节点1 binlog 信息
MASTER_LOG_POS=821; #节点1 log_pos信息
```
2. 开启主从同步
```sql
start slave;
```
3. 查看同步状态
```sql
show slave status\G;
```
## Mysql 配置密码等级
```bash
set global validate_password.policy=0;
set global validate_password.mixed_case_count=0;
set global validate_password.number_count=0;
set global validate_password.special_char_count=0;
set global validate_password.length=3;
```
> 1.修改密码强度等级为0即是LOW;
> 2.修改密码至少要包含的大写字母和小写字母的个数为0;
> 3.修改密码至少要包含的数字个数为0;
> 4.修改密码至少要包含的特殊字符的个数为0;
> 5.修改密码的长度最小个数为3;

View File

@@ -0,0 +1,23 @@
> 本文作者:丁辉
# Nexus忘记密码
1. 启动服务
```bash
java -jar ./lib/support/nexus-orient-console.jar
```
2. 进入数据库
```bash
connect plocal:../sonatype-work/nexus3/db/security admin admin
```
3. 重置密码
```bash
update user SET password="$shiro1$SHA-512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"
```

View File

@@ -0,0 +1,86 @@
> 本文作者:丁辉
# OpenSSL搭建CA证书颁发机构Genpkey
[官网文档](https://www.openssl.org/docs/man3.0/man1/openssl-genpkey.html)
## 基础环境准备
1. 安装 OpenSSL
- Centos
```bash
yum install openssl -y
```
- Ubuntu
```bash
apt install openssl -y
```
## 创建根证书颁发机构
1. 生成 CA 私钥
```bash
openssl genpkey -algorithm RSA -out RootCA.key
```
> -pkeyopt rsa_keygen_bits:4096 -aes256
2. 生成 CA 自签名证书
```bash
openssl req -key RootCA.key -new -x509 -days 3650 -out RootCA.pem -subj "/C=CN/ST=Beijing/L=Beijing/O=Linux/OU=Linux/CN=*.com"
```
`-subj`后面跟着的是一个字符串用于指定证书的主题Subject字段。这些字段包含了证书所有者的识别信息通常用于证书显示和验证过程中。各个字段的意义如下
- `/C=CN`:国家名称,使用两位国家代码,例如 `CN` 代表中国。
- `/ST=YourState`:州或省份名称,根据你的地理位置填写。
- `/L=YourCity`:城市名称,根据你的地理位置填写。
- `/O=YourOrganization`:组织名称,表示证书所有者所属的公司或组织。
- `/OU=YourOrganizationalUnit`:组织单位名称,是组织内部的一个部门或单位。
- `/CN=YourCommonName`:常用名称,通常是域名或个人的名称。对于根 CA这里可以是机构的名称或描述。
- `/emailAddress=your.email@example.com`:电子邮件地址,用于联系证书的所有者。
## 创建并签署子证书(这里演示为泛域名证书)
1. 生成子证书密钥
```bash
openssl genpkey -algorithm RSA -out wildcard.key
```
2. 创建证书签名请求(CSR)
> 使用子证书的私钥创建一个 CSR。CSR 包含证书的相关信息。
```bash
openssl req -new -key wildcard.key -out wildcard.csr -subj "/C=CN/ST=Beijing/L=Beijing/O=Linux/OU=Linux/CN=*.com"
```
3. 使用根证书签署子证书
```bash
openssl x509 -req -days 3650 -in wildcard.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -out wildcard.crt -sha256
```
## 分发证书
> 将子证书server.pem和根证书RootCA.pem分发给需要验证身份的用户或系统。
### 注意事项:
- **安全性**:确保私钥文件(如 RootCA.key 和 server.key安全存储避免泄露。
- **有效期**:根证书通常具有较长的有效期(如 10 年),而子证书具有较短的有效期(如 1 年)。根据你的安全政策调整这些设置。
- **撤销列表CRL和在线证书状态协议OCSP**:为了提高安全性,建立机制以撤销或检查证书的有效性。
> 这只是创建 CA 和管理证书的基本概念。实际操作中,可能需要考虑更多的安全措施和复杂的配置选项。
```bash
openssl pkcs12 -export -out RootCA.pfx -inkey RootCA.key -in RootCA.pem
```

Some files were not shown because too many files have changed in this diff Show More