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

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

View File

@@ -0,0 +1,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
```