# 系统分析 # 账户权限 ## 账户 #### 查询信息 - 查询用户 【lihao】 ``` id lihao ``` #### 新建用户 - 新建一位用户名为 【lihao】,个人目录【/home/lihao】, ``` adduser lihao useradd -m -d /opt/username username ``` ## 权限 - 查询目录、文件夹、文件 ``` ls #列出当前目录中的所有文件夹和文件 ls -lh #列出当前目录中的所有文件夹和文件(长列表格式) ls -ls #列出当前目录中的所有文件夹和文件(以大小排序) ls -a #列出当前目录中的隐藏文件夹和文件 ls -la #列出当前目录中的隐藏文件夹和文件(长列表格式) ls .. #列出当前目录的父目录中的文件夹和文件 ls / #列出根目录中的所有文件夹和文件 ls -R #列出系统中的所有目录和子目录中的所有文件夹和文件 ``` ## 解析 - `ls` 列出当前目录中的所有文件夹和文件 [![image-1658965719762.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/yHO7lgtGwm8Yju8U-image-1658965719762.png)](http://book.321jr.com/uploads/images/gallery/2022-07/yHO7lgtGwm8Yju8U-image-1658965719762.png) - `ls -lh`列出当前目录中的所有文件夹和文件(长列表格式) [![image-1658965788768.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/wdJqNGa3KRw2wA1y-image-1658965788768.png)](http://book.321jr.com/uploads/images/gallery/2022-07/wdJqNGa3KRw2wA1y-image-1658965788768.png) - 更多细节详见(表1)
表 1
文件类型权限链接数所有者群组文件大小上次修改日期文件名
-rw-rw-r--1adminadmin137.28 07:40321jn.txt
-rw-rw-r--1adminadmin137.28 06:56321jr.txt
# IP 地址规范 ##### IP 地址 - 192.168.2.0 - 192.168.2.249 ##### 固定段 - 192.168.2. ,共 1个段 ##### 使用位 - 0、1、2 ... 249,共 250位 ##### 分配区 - A、B、C、D、E、F、G、H、I、J,共 10个区 ##### 区位数
范围 区位 IP 地址数量
A 基础硬件 0~9 0 1 2 3 4 5 6 7 8 9 10
B 基础系统 10~19 10 11 12 13 14 15 16 17 18 19 10
C 基础数据 20~29 20 21 22 23 24 25 26 27 28 29 10
D 应用程序 30~49 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 20
E 公共营销 50~69 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 20
F 安防布控 70~89 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 20
G WiFi通信 90~99 90 91 92 93 94 95 96 97 98 99 10
H 电脑设备 100~129 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 30
I 手机通信 130~199 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 912 193 194 195 196 197 198 199 70
J 智能物联 200~249 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 50
# 端口规范 ##### 端口号 - 外网:10010-62490,端口规范 - 内网:21、22、80、443 ,协议规范 ##### 结构 - 内网端口号:外网端口号 ##### 外网端口号 10010 = AXXXB - A=\[1,2,3,4,5\] - E\[0,1,2,3,4,5,6,7,8,9\] - XXX\[0,1,2,3...249\]=IP地址 ##### 端口规范
内端口号 外部端口尾号 外端口号 协议 用途
80/443 01\*\*\*0TCPweb
22 11\*\*\*1 ssh
2198 21\*\*\*2 kvm
5900 31\*\*\*3 vnc
##### ##### 协议规范# 导入 # 容器 # Docker 命令 #### 查询 ``` docker ps -q #列出所有正在运行的容器 ``` #### 开始 ``` docker start myrunoob #启动已被停止的容器 myrunoob docker restart myrunoob #重启容器 myrunoob ``` #### 停止 ``` docker stop myrunoob #停止运行中的容器 myrunoob docker kill -s KILL mynginx #停止运行中的容器 mynginx ``` #### #### 清理命令 杀死所有正在运行的容器 ``` docker kill $(docker ps -a -q) ``` 删除所有已经停止的容器 ``` docker rm $(docker ps -a -q) ``` 删除所有未打 dangling 标签的镜像 ``` docker rmi $(docker images -q -f dangling=true) ``` 通过镜像的id来删除指定镜像 ``` docker rmi ``` 删除所有镜像 ``` docker rmi $(docker images -q) ``` - - - - - - # Docker 命令大全 #### 容器生命周期管理 - [run](https://www.runoob.com/docker/docker-run-command.html) - [start/stop/restart](https://www.runoob.com/docker/docker-start-stop-restart-command.html) - [kill](https://www.runoob.com/docker/docker-kill-command.html) - [rm](https://www.runoob.com/docker/docker-rm-command.html) - [pause/unpause](https://www.runoob.com/docker/docker-pause-unpause-command.html) - [create](https://www.runoob.com/docker/docker-create-command.html) - [exec](https://www.runoob.com/docker/docker-exec-command.html) #### 容器操作 - [ps](https://www.runoob.com/docker/docker-ps-command.html) - [inspect](https://www.runoob.com/docker/docker-inspect-command.html) - [top](https://www.runoob.com/docker/docker-top-command.html) - [attach](https://www.runoob.com/docker/docker-attach-command.html) - [events](https://www.runoob.com/docker/docker-events-command.html) - [logs](https://www.runoob.com/docker/docker-logs-command.html) - [wait](https://www.runoob.com/docker/docker-wait-command.html) - [export](https://www.runoob.com/docker/docker-export-command.html) - [port](https://www.runoob.com/docker/docker-port-command.html) - [stats](https://www.runoob.com/docker/docker-stats-command.html) #### 容器rootfs命令 - [commit](https://www.runoob.com/docker/docker-commit-command.html) - [cp](https://www.runoob.com/docker/docker-cp-command.html) - [diff](https://www.runoob.com/docker/docker-diff-command.html) #### 镜像仓库 - [login](https://www.runoob.com/docker/docker-login-command.html) - [pull](https://www.runoob.com/docker/docker-pull-command.html) - [push](https://www.runoob.com/docker/docker-push-command.html) - [search](https://www.runoob.com/docker/docker-search-command.html) #### 本地镜像管理 - [images](https://www.runoob.com/docker/docker-images-command.html) - [rmi](https://www.runoob.com/docker/docker-rmi-command.html) - [tag](https://www.runoob.com/docker/docker-tag-command.html) - [build](https://www.runoob.com/docker/docker-build-command.html) - [history](https://www.runoob.com/docker/docker-history-command.html) - [save](https://www.runoob.com/docker/docker-save-command.html) - [load](https://www.runoob.com/docker/docker-load-command.html) - [import](https://www.runoob.com/docker/docker-import-command.html) #### info|version - [info](https://www.runoob.com/docker/docker-info-command.html) - [version](https://www.runoob.com/docker/docker-version-command.html) # 命令 Linux 内核 debian docker # Debian 常用指令 ### 网络管理 #### 建立网络接口配置文件 - 为 *eth0* 设备建立启用静态 IP 的示例文件 ``` cd /etc/sysconfig/ cat > ifconfig.eth0 << "EOF" ONBOOT=yes IFACE=eth0 SERVICE=ipv4-static IP=192.168.1.2 GATEWAY=192.168.1.1 PREFIX=24 BROADCAST=192.168.1.255 EOF ``` #### IP 地址 - 检查主机上的可用网络接口 ``` ip link ``` - 设置静态 IP 地址 ``` nano /etc/network/interfaces ``` - - 使用默认设置,您的网络接口配置文件将如下所示:[![image-1659106861909.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/hcL7qDY7wwipkdXu-image-1659106861909.png) ](http://book.321jr.com/uploads/images/gallery/2022-07/hcL7qDY7wwipkdXu-image-1659106861909.png) - 添加有关您的网络接口的以下详细信息,例如您要设置的静态IP 地址、网络掩码、网关、dns-nameservers: [![image-1659107020086.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/Sj8RZc3KNtLZNYHV-image-1659107020086.png)](http://book.321jr.com/uploads/images/gallery/2022-07/Sj8RZc3KNtLZNYHV-image-1659107020086.png) #### DNS - DNS 服务器的 IP 地址填入 `/etc/resolv.conf` 文件 ``` cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf domain nameserver nameserver # End /etc/resolv.conf EOF ``` #### 系统主机名 - 通过以下命令建立 `/etc/hostname` 文件且向其中写入主机名。*``* 替换为你想要设置的名称。请不要输入完整域名(Fully Qualified Domain Name,FQDN),那应该是放在 `/etc/hosts` 文件中的信息。 ``` echo "" > /etc/hostname ``` #### IP:域名 - 通过以下命令建立 `/etc/hosts` 文件。其中,*`<192.168.1.1>`*,*``*,和 *``* 的值应该根据用户和实际需要进行更改(如果已经通过网络/系统管理员获得了 IP 地址,那么设备就可以连接到已存在的网络)。其中可选的别名可以忽略。 ``` cat > /etc/hosts << "EOF" # Begin /etc/hosts 127.0.0.1 localhost 127.0.1.1 <192.168.1.1> [alias1] [alias2 ...] ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters # End /etc/hosts EOF ``` ### 软件包 ##### 安装 - 安装软件包 foo ``` apt-get update #更新软件包库数据 apt-get -y install foo #安装“foo”包的最新版本及其依赖项 ``` ##### 卸载 - 卸载软件包 foo ``` apt-get remove foo #仅卸载"foo"包 apt-get -y autoremove foo #卸载 Debian 11不再需要的"foo"包及其依赖项 ``` ##### 删除 - 删除软件包 foo ``` apt-get -y purge foo #删除"foo"包配置和数据 apt-get -y autoremove --purge foo #删除"foo"包配置、数据及其所有依赖项 ``` ##### 更新 - 更新软件包数据库 ``` apt-get upgrade #更新并安装已安装软件包的最新版本而不删除任何其他软件包 apt-get dist-upgrade #更新并安装已安装软件包的最新版本,同时根据需要删除其他软件包 ``` ##### 查询 - 查询主机上安装的所有软件包 ``` dpkg --list ``` - 显示有关“foo ”包的详细信息 ``` apt-cache show foo ``` ##### 配置 - 仓库地址配置文件 ``` nano /etc/yum.repos.d ``` ### ssh ##### 远程登录 - 开启端口 22 ``` nano /etc/ssh/sshd_config #打开 sshd_config文件 #port 22 #找到此行,如下图1 port 22 #更改为此行,如下图2(去掉开头"#") ``` - - 图1 [![image-1659100343337.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/MroaI0umYMQunQ3i-image-1659100343337.png)](http://book.321jr.com/uploads/images/gallery/2022-07/MroaI0umYMQunQ3i-image-1659100343337.png) - 图2 [![image-1659100389776.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/THfh5jTyE2pajp0Z-image-1659100389776.png)](http://book.321jr.com/uploads/images/gallery/2022-07/THfh5jTyE2pajp0Z-image-1659100389776.png) - 开启 root登录 ``` #PermitRootLogin prohibi-password #找到此行,如下图3 PermitRootLogin yes #更改为此行,如下图4(去掉开头 "#","yes"代替"prohibi-password" #PasswordAuthentication yes #找到此行 PasswordAuthentication yes #更改为此行(去掉开头"#"),如下图5 ``` - - 图3 [![image-1659100445724.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/xMJWV0KdY5NbTEqn-image-1659100445724.png)](http://book.321jr.com/uploads/images/gallery/2022-07/xMJWV0KdY5NbTEqn-image-1659100445724.png) - 图4 [![image-1659099151211.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/oq0xCOpFMd049XN3-image-1659099151211.png)](http://book.321jr.com/uploads/images/gallery/2022-07/oq0xCOpFMd049XN3-image-1659099151211.png) - 图5 [![image-1659208230852.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/GUBNP9S1vsmSCEE9-image-1659208230852.png)](http://book.321jr.com/uploads/images/gallery/2022-07/GUBNP9S1vsmSCEE9-image-1659208230852.png) - 退出 nano,按 [![image-1659100718686.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/gCcKVkpBPtXronlI-image-1659100718686.png) ](http://book.321jr.com/uploads/images/gallery/2022-07/gCcKVkpBPtXronlI-image-1659100718686.png)后,再按"y",显示如下图6,最后按“回车”,显示如下图7 - 图6 [![image-1659100647925.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/Cf05fMcHwMYXRFRB-image-1659100647925.png)](http://book.321jr.com/uploads/images/gallery/2022-07/Cf05fMcHwMYXRFRB-image-1659100647925.png) - 图7 [![image-1659101015309.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/LzRxhv3gxtGLwZvn-image-1659101015309.png)](http://book.321jr.com/uploads/images/gallery/2022-07/LzRxhv3gxtGLwZvn-image-1659101015309.png) - 重启 sshd服务 ``` systemctl restart sshd ``` ### Docker 安装 - 官方安装脚本自动安装 ``` curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun ``` - 删除安装包 ``` apt-get purge docker-ce ``` - 删除镜像、容器、配置文件等内容 ``` rm -rf /var/lib/docker ``` # SSH 密钥登录 #### 前言 我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器。但是,一般的密码方式登录,容易有密码被暴力破解的问题。所以,一般我们会将 SSH 的端口设置为默认的 22 以外的端口,或者禁用 root 账户登录。其实,有一个更好的办法来保证安全,而且让你可以放心地用 root 账户从远程登录——那就是通过密钥方式登录。 密钥形式登录的原理是:利用密钥生成器制作一对密钥——一只公钥和一只私钥。将公钥添加到服务器的某个账户上,然后在客户端利用私钥即可完成认证并登录。这样一来,没有私钥,任何人都无法通过 SSH 暴力破解你的密码来远程登录到系统。此外,如果将公钥复制到其他账户甚至主机,利用私钥也可以登录。 下面来讲解如何在 Linux 服务器上制作密钥对,将公钥添加给账户,设置 SSH,最后通过客户端登录。 #### 制作密钥对 - 首先在服务器上制作密钥对。首先用密码登录到你打算使用密钥登录的账户,然后执行以下命令
``` [root@host ~]$ ssh-keygen <== 建立密钥对 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): <== Enter Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空 Enter same passphrase again: <== 再输入一遍密钥锁码 Your identification has been saved in /root/.ssh/id_rsa. <== 私钥 Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥 The key fingerprint is: 0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host ```
- 密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。 - 现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id\_rsa 为私钥,id\_rsa.pub 为公钥。 #### 在服务器上安装公钥 - 键入以下命令,在服务器上安装公钥
``` [root@host ~]$ cd .ssh [root@host .ssh]$ cat id_rsa.pub >> authorized_keys ```
- 如此便完成了公钥的安装。为了确保连接成功,请保证以下文件权限正确
``` [root@host .ssh]$ chmod 600 authorized_keys [root@host .ssh]$ chmod 700 ~/.ssh ```
#### 设置 SSH,打开密钥登录功能 - 编辑 /etc/ssh/sshd\_config 文件,进行如下设置
``` RSAAuthentication yes PubkeyAuthentication yes ```
- 另外,请留意 root 用户能否通过 SSH 登录
``` PermitRootLogin yes ```
- 当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录
``` PasswordAuthentication no ```
- 最后,重启 SSH 服务
``` [root@host .ssh]$ service sshd restart ```
#### 将私钥下载到客户端,然后转换为 PuTTY 能使用的格式 使用 WinSCP、SFTP 等工具将私钥文件 id\_rsa 下载到客户端机器上。然后打开 PuTTYGen,单击 Actions 中的 Load 按钮,载入你刚才下载到的私钥文件。如果你刚才设置了密钥锁码,这时则需要输入。 载入成功后,PuTTYGen 会显示密钥相关的信息。在 Key comment 中键入对密钥的说明信息,然后单击 Save private key 按钮即可将私钥文件存放为 PuTTY 能使用的格式。 今后,当你使用 PuTTY 登录时,可以在左侧的 Connection -> SSH -> Auth 中的 Private key file for authentication: 处选择你的私钥文件,然后即可登录了,过程中只需输入密钥锁码即可。 # Linux 常用命令 ## 系统信息 ``` arch #显示机器的处理器架构(1) uname -m #显示机器的处理器架构(2) uname -r #显示正在使用的内核版本 dmidecode -q #显示硬件系统部件 - (SMBIOS / DMI) hdparm -i /dev/hda #罗列一个磁盘的架构特性 hdparm -tT /dev/sda #在磁盘上执行测试性读取操作 cat /proc/cpuinfo #显示CPU info的信息 cat /proc/interrupts #显示中断 cat /proc/meminfo #校验内存使用 cat /proc/swaps #显示哪些swap被使用 cat /proc/version #显示内核的版本 cat /proc/net/dev #显示网络适配器及统计 cat /proc/mounts #显示已加载的文件系统 lspci -tv #罗列 PCI 设备 lsusb -tv #显示 USB 设备 date #显示系统日期 cal 2007 #显示2007年的日历表 date 041217002007.00 #设置日期和时间 - 月日时分年.秒 clock -w #将时间修改保存到 BIOS ``` ## 关机 (系统的关机、重启以及登出 ) ``` shutdown -h now #关闭系统(1) init 0 #关闭系统(2) telinit 0 #关闭系统(3) shutdown -h hours:minutes & #按预定时间关闭系统 shutdown -c #取消按预定时间关闭系统 shutdown -r now #重启(1) reboot #重启(2) logout #注销 ``` ## 文件和目录 ``` cd /home #进入 '/ home' 目录' cd .. #返回上一级目录 cd ../.. #返回上两级目录 cd #进入个人的主目录 cd ~user1 #进入个人的主目录 cd - #返回上次所在的目录 pwd #显示工作路径 ls #查看目录中的文件 ls -F #查看目录中的文件 ls -l #显示文件和目录的详细资料 ls -a #显示隐藏文件 ls *[0-9]* #显示包含数字的文件名和目录名 tree #显示文件和目录由根目录开始的树形结构(1) lstree #显示文件和目录由根目录开始的树形结构(2) mkdir dir1 #创建一个叫做 'dir1' 的目录' mkdir dir1 dir2 #同时创建两个目录 mkdir -p /tmp/dir1/dir2 #创建一个目录树 rm -f file1 #删除一个叫做 'file1' 的文件' rmdir dir1 #删除一个叫做 'dir1' 的目录' rm -rf dir1 #删除一个叫做 'dir1' 的目录并同时删除其内容 rm -rf dir1 dir2 #同时删除两个目录及它们的内容 mv dir1 new_dir #重命名/移动 一个目录 cp file1 file2 #复制一个文件 cp dir/* . #复制一个目录下的所有文件到当前工作目录 cp -a /tmp/dir1 . #复制一个目录到当前工作目录 cp -a dir1 dir2 #复制一个目录 ln -s file1 lnk1 #创建一个指向文件或目录的软链接 ln file1 lnk1 #创建一个指向文件或目录的物理链接 touch -t 0712250000 file1 #修改一个文件或目录的时间戳 - (YYMMDDhhmm) iconv -l #列出已知的编码 ``` ## 文件搜索 ``` find / -name file1 #从 '/' 开始进入根文件系统搜索文件和目录 find / -user user1 #搜索属于用户 'user1' 的文件和目录 find /home/user1 -name \*.bin #在目录 '/ home/user1' 中搜索带有'.bin' 结尾的文件 find /usr/bin -type f -atime +100 #搜索在过去100天内未被使用过的执行文件 find /usr/bin -type f -mtime -10 #搜索在10天内被创建或者修改过的文件 find / -name \*.rpm -exec chmod 755 '{}' \; #搜索以 '.rpm' 结尾的文件并定义其权限 find / -xdev -name \*.rpm #搜索以 '.rpm' 结尾的文件,忽略光驱、捷盘等可移动设备 locate \*.ps #寻找以 '.ps' 结尾的文件 - 先运行 'updatedb' 命令 whereis halt #显示一个二进制文件、源码或man的位置 which halt #显示一个二进制文件或可执行文件的完整路径 ``` ## 挂载一个文件系统 ``` mount /dev/hda2 /mnt/hda2 #挂载一个叫做hda2的盘 - 确定目录 '/ mnt/hda2' 已经存在 umount /dev/hda2 #卸载一个叫做hda2的盘 - 先从挂载点 '/ mnt/hda2' 退出 fuser -km /mnt/hda2 #当设备繁忙时强制卸载 umount -n /mnt/hda2 #运行卸载操作而不写入 /etc/mtab 文件- 当文件为只读或当磁盘写满时非常有用 mount /dev/fd0 /mnt/floppy #挂载一个软盘 mount /dev/cdrom /mnt/cdrom #挂载一个cdrom或dvdrom mount /dev/hdc /mnt/cdrecorder #挂载一个cdrw或dvdrom mount /dev/hdb /mnt/cdrecorder #挂载一个cdrw或dvdrom mount -o loop file.iso /mnt/cdrom #挂载一个文件或ISO镜像文件 mount -t vfat /dev/hda5 /mnt/hda5 #挂载一个Windows FAT32文件系统 mount /dev/sda1 /mnt/usbdisk #挂载一个usb 捷盘或闪存设备 mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share #挂载一个windows网络共享 ``` ## 磁盘空间 ``` df -h #显示已经挂载的分区列表 ls -lSr |more #以尺寸大小排列文件和目录 du -sh dir1 #估算目录 'dir1' 已经使用的磁盘空间' du -sk * | sort -rn #以容量大小为依据依次显示文件和目录的大小 rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n #以大小为依据依次显示已安装的rpm包所使用的空间 (fedora, redhat类系统) dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n #以大小为依据显示已安装的deb包所使用的空间 (ubuntu, debian类系统) ``` ## 用户和群组 ``` groupadd group_name #创建一个新用户组 groupdel group_name #删除一个用户组 groupmod -n new_group_name old_group_name #重命名一个用户组 useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 #创建一个属于 "admin" 用户组的用户 useradd user1 创建一个新用户 userdel -r user1 #删除一个用户 ( '-r' 排除主目录) usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 #修改用户属性 passwd 修改口令 passwd user1 #修改一个用户的口令 (只允许root执行) chage -E 2005-12-31 user1 #设置用户口令的失效期限 pwck #检查 '/etc/passwd' 的文件格式和语法修正以及存在的用户 grpck #检查 '/etc/passwd' 的文件格式和语法修正以及存在的群组 newgrp group_name #登陆进一个新的群组以改变新创建文件的预设群组 ``` ## 文件的权限 - 使用 "+" 设置权限,使用 "-" 用于取消 ``` ls -lh #显示权限 ls /tmp | pr -T5 -W$COLUMNS #将终端划分成5栏显示 chmod ugo+rwx directory1 #设置目录的所有人(u)、群组(g)以及其他人(o)以读(r )、写(w)和执行(x)的权限 chmod go-rwx directory1 #删除群组(g)与其他人(o)对目录的读写执行权限 chown user1 file1 #改变一个文件的所有人属性 chown -R user1 directory1 #改变一个目录的所有人属性并同时改变改目录下所有文件的属性 chgrp group1 file1 #改变文件的群组 chown user1:group1 file1 #改变一个文件的所有人和群组属性 find / -perm -u+s #罗列一个系统中所有使用了SUID控制的文件 chmod u+s /bin/file1 #设置一个二进制文件的 SUID 位 - 运行该文件的用户也被赋予和所有者同样的权限 chmod u-s /bin/file1 #禁用一个二进制文件的 SUID位 chmod g+s /home/public #设置一个目录的SGID 位 - 类似SUID ,不过这是针对目录的 chmod g-s /home/public #禁用一个目录的 SGID 位 chmod o+t /home/public #设置一个文件的 STIKY 位 - 只允许合法所有人删除文件 chmod o-t /home/public #禁用一个目录的 STIKY 位 ``` ## 文件的特殊属性 - 使用 "+" 设置权限,使用 "-" 用于取消 ``` chattr +a file1 #只允许以追加方式读写文件 chattr +c file1 #允许这个文件能被内核自动压缩/解压 chattr +d file1 #在进行文件系统备份时,dump程序将忽略这个文件 chattr +i file1 #设置成不可变的文件,不能被删除、修改、重命名或者链接 chattr +s file1 #允许一个文件被安全地删除 chattr +S file1 #一旦应用程序对这个文件执行了写操作,使系统立刻把修改的结果写到磁盘 chattr +u file1 #若文件被删除,系统会允许你在以后恢复这个被删除的文件 lsattr #显示特殊的属性 ``` ## 打包和压缩文件 ``` bunzip2 file1.bz2 #解压一个叫做 'file1.bz2'的文件 bzip2 file1 #压缩一个叫做 'file1' 的文件 gunzip file1.gz #解压一个叫做 'file1.gz'的文件 gzip file1 #压缩一个叫做 'file1'的文件 gzip -9 file1 #最大程度压缩 rar a file1.rar test_file #创建一个叫做 'file1.rar' 的包 rar a file1.rar file1 file2 dir1 #同时压缩 'file1', 'file2' 以及目录 'dir1' rar x file1.rar #解压rar包 unrar x file1.rar #解压rar包 tar -cvf archive.tar file1 #创建一个非压缩的 tarball tar -cvf archive.tar file1 file2 dir1 #创建一个包含了 'file1', 'file2' 以及 'dir1'的档案文件 tar -tf archive.tar #显示一个包中的内容 tar -xvf archive.tar #释放一个包 tar -xvf archive.tar -C /tmp #将压缩包释放到 /tmp目录下 tar -cvfj archive.tar.bz2 dir1 #创建一个bzip2格式的压缩包 tar -xvfj archive.tar.bz2 #解压一个bzip2格式的压缩包 tar -cvfz archive.tar.gz dir1 #创建一个gzip格式的压缩包 tar -xvfz archive.tar.gz #解压一个gzip格式的压缩包 zip file1.zip file1 #创建一个zip格式的压缩包 zip -r file1.zip file1 file2 dir1 #将几个文件和目录同时压缩成一个zip格式的压缩包 unzip file1.zip #解压一个zip格式压缩包 ``` ## ## APT 软件工具 (Debian, Ubuntu 以及类似系统) ``` apt-get install package_name #安装/更新一个 deb 包 apt-cdrom install package_name #从光盘安装/更新一个 deb 包 apt-get update #升级列表中的软件包 apt-get upgrade #升级所有已安装的软件 apt-get remove package_name #从系统删除一个deb包 apt-get check #确认依赖的软件仓库正确 apt-get clean #从下载的软件包中清理缓存 apt-cache search searched-package #返回包含所要搜索字符串的软件包名称 ``` ## 查看文件内容 ``` cat file1 从第一个字节开始正向查看文件的内容 tac file1 从最后一行开始反向查看一个文件的内容 more file1 查看一个长文件的内容 less file1 类似于 'more' 命令,但是它允许在文件中和正向操作一样的反向操作 head -2 file1 查看一个文件的前两行 tail -2 file1 查看一个文件的最后两行 tail -f /var/log/messages 实时查看被添加到一个文件中的内容 ``` ## 文本处理 ``` cat file1 file2 ... | command <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT cat file1 | command( sed, grep, awk, grep, etc...) > result.txt 合并一个文件的详细说明文本,并将简介写入一个新文件中 cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt 合并一个文件的详细说明文本,并将简介写入一个已有的文件中 grep Aug /var/log/messages 在文件 '/var/log/messages'中查找关键词"Aug" grep ^Aug /var/log/messages 在文件 '/var/log/messages'中查找以"Aug"开始的词汇 grep [0-9] /var/log/messages 选择 '/var/log/messages' 文件中所有包含数字的行 grep Aug -R /var/log/* 在目录 '/var/log' 及随后的目录中搜索字符串"Aug" sed 's/stringa1/stringa2/g' example.txt 将example.txt文件中的 "string1" 替换成 "string2" sed '/^$/d' example.txt 从example.txt文件中删除所有空白行 sed '/ *#/d; /^$/d' example.txt 从example.txt文件中删除所有注释和空白行 echo 'esempio' | tr '[:lower:]' '[:upper:]' 合并上下单元格内容 sed -e '1d' result.txt 从文件example.txt 中排除第一行 sed -n '/stringa1/p' 查看只包含词汇 "string1"的行 sed -e 's/ *$//' example.txt 删除每一行最后的空白字符 sed -e 's/stringa1//g' example.txt 从文档中只删除词汇 "string1" 并保留剩余全部 sed -n '1,5p;5q' example.txt 查看从第一行到第5行内容 sed -n '5p;5q' example.txt 查看第5行 sed -e 's/00*/0/g' example.txt 用单个零替换多个零 cat -n file1 标示文件的行数 cat example.txt | awk 'NR%2==1' 删除example.txt文件中的所有偶数行 echo a b c | awk '{print $1}' 查看一行第一栏 echo a b c | awk '{print $1,$3}' 查看一行的第一和第三栏 paste file1 file2 合并两个文件或两栏的内容 paste -d '+' file1 file2 合并两个文件或两栏的内容,中间用"+"区分 sort file1 file2 排序两个文件的内容 sort file1 file2 | uniq 取出两个文件的并集(重复的行只保留一份) sort file1 file2 | uniq -u 删除交集,留下其他的行 sort file1 file2 | uniq -d 取出两个文件的交集(只留下同时存在于两个文件中的文件) comm -1 file1 file2 比较两个文件的内容只删除 'file1' 所包含的内容 comm -2 file1 file2 比较两个文件的内容只删除 'file2' 所包含的内容 comm -3 file1 file2 比较两个文件的内容只删除两个文件共有的部分 ``` ## 字符设置和文件格式转换 ``` dos2unix filedos.txt fileunix.txt #将一个文本文件的格式从MSDOS转换成UNIX unix2dos fileunix.txt filedos.txt #将一个文本文件的格式从UNIX转换成MSDOS recode ..HTML < page.txt > page.html #将一个文本文件转换成html recode -l | more #显示所有允许的转换格式 ``` ## 文件系统分析 ``` badblocks -v /dev/hda1 检查磁盘hda1上的坏磁块 fsck /dev/hda1 修复/检查hda1磁盘上linux文件系统的完整性 fsck.ext2 /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性 e2fsck /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性 e2fsck -j /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性 fsck.ext3 /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性 fsck.vfat /dev/hda1 修复/检查hda1磁盘上fat文件系统的完整性 fsck.msdos /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性 dosfsck /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性 ``` ## 初始化一个文件系统 ``` mkfs /dev/hda1 在hda1分区创建一个文件系统 mke2fs /dev/hda1 在hda1分区创建一个linux ext2的文件系统 mke2fs -j /dev/hda1 在hda1分区创建一个linux ext3(日志型)的文件系统 mkfs -t vfat 32 -F /dev/hda1 创建一个 FAT32 文件系统 fdformat -n /dev/fd0 格式化一个软盘 mkswap /dev/hda3 创建一个swap文件系统 ``` ## SWAP文件系统 ``` mkswap /dev/hda3 创建一个swap文件系统 swapon /dev/hda3 启用一个新的swap文件系统 swapon /dev/hda2 /dev/hdb3 启用两个swap分区 ``` ## 备份 ``` dump -0aj -f /tmp/home0.bak /home 制作一个 '/home' 目录的完整备份 dump -1aj -f /tmp/home0.bak /home 制作一个 '/home' 目录的交互式备份 restore -if /tmp/home0.bak 还原一个交互式备份 rsync -rogpav --delete /home /tmp 同步两边的目录 rsync -rogpav -e ssh --delete /home ip_address:/tmp 通过SSH通道rsync rsync -az -e ssh --delete ip_addr:/home/public /home/local 通过ssh和压缩将一个远程目录同步到本地目录 rsync -az -e ssh --delete /home/local ip_addr:/home/public 通过ssh和压缩将本地目录同步到远程目录 dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' 通过ssh在远程主机上执行一次备份本地磁盘的操作 dd if=/dev/sda of=/tmp/file1 备份磁盘内容到一个文件 tar -Puf backup.tar /home/user 执行一次对 '/home/user' 目录的交互式备份操作 ( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' 通过ssh在远程目录中复制一个目录内容 ( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' 通过ssh在远程目录中复制一个本地目录 tar cf - . | (cd /tmp/backup ; tar xf - ) 本地将一个目录复制到另一个地方,保留原有权限及链接 find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents 从一个目录查找并复制所有以 '.txt' 结尾的文件到另一个目录 find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 查找所有以 '.log' 结尾的文件并做成一个bzip包 dd if=/dev/hda of=/dev/fd0 bs=512 count=1 做一个将 MBR (Master Boot Record)内容复制到软盘的动作 dd if=/dev/fd0 of=/dev/hda bs=512 count=1 从已经保存到软盘的备份中恢复MBR内容 ``` ## 光盘 ``` cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force 清空一个可复写的光盘内容 mkisofs /dev/cdrom > cd.iso 在磁盘上创建一个光盘的iso镜像文件 mkisofs /dev/cdrom | gzip > cd_iso.gz 在磁盘上创建一个压缩了的光盘iso镜像文件 mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd 创建一个目录的iso镜像文件 cdrecord -v dev=/dev/cdrom cd.iso 刻录一个ISO镜像文件 gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - 刻录一个压缩了的ISO镜像文件 mount -o loop cd.iso /mnt/iso 挂载一个ISO镜像文件 cd-paranoia -B 从一个CD光盘转录音轨到 wav 文件中 cd-paranoia -- "-3" 从一个CD光盘转录音轨到 wav 文件中(参数-3) cdrecord --scanbus 扫描总线以识别scsi通道 dd if=/dev/hdc | md5sum 校验一个设备的md5sum编码,例如一张 CD ``` ## 网络 - (以太网和WIFI无线) ``` ifconfig eth0 显示一个以太网卡的配置 ifup eth0 启用一个 'eth0' 网络设备 ifdown eth0 禁用一个 'eth0' 网络设备 ifconfig eth0 192.168.1.1 netmask 255.255.255.0 控制IP地址 ifconfig eth0 promisc 设置 'eth0' 成混杂模式以嗅探数据包 (sniffing) dhclient eth0 以dhcp模式启用 'eth0' route -n show routing table route add -net 0/0 gw IP_Gateway configura default gateway route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16' route del 0/0 gw IP_gateway remove static route echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing hostname show hostname of system host www.example.com lookup hostname to resolve name to ip address and viceversa(1) nslookup www.example.com lookup hostname to resolve name to ip address and viceversa(2) ip link show show link status of all interfaces mii-tool eth0 show link status of 'eth0' ethtool eth0 show statistics of network card 'eth0' netstat -tup show all active network connections and their PID netstat -tupl show all network services listening on the system and their PID tcpdump tcp port 80 show all HTTP traffic iwlist scan show wireless networks iwconfig eth1 show configuration of a wireless network card hostname show hostname host www.example.com lookup hostname to resolve name to ip address and viceversa nslookup www.example.com lookup hostname to resolve name to ip address and viceversa whois www.example.com lookup on Whois database ``` ## Microsoft Windows networks (SAMBA) ``` nbtscan ip_addr netbios name resolution nmblookup -A ip_addr netbios name resolution smbclient -L ip_addr/hostname show remote shares of a windows host smbget -Rr smb://ip_addr/share like wget can download files from a host windows via smb mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share ``` # 内核 内存管理 进程管理 设备驱动程序 系统调用和安全防护 # 设置进程限制 ## ulimit
#### 格式 ulimit \[-SHaAcdfMnst\] \[num\]
#### 描述 ulimit 设置或显示用户创建的进程的资源限制。
#### 选项 **-S **设置或显示软限制。可以将软限制修改为小于或等于硬限制的任何值。对于某些资源值,软限制不能设置为低于现有使用量。 **-H **设置或显示硬限制。硬限制可以降低到任何大于或等于软限制的值。硬限制只能由具有超级用户权限的进程提高。 **-a** 显示所有可用的资源限制。 **-A** 设置或显示进程的最大地址空间大小,以 1024 字节为单位。如果超出限制,存储分配请求和自动堆栈增长将失败。尝试将地址空间大小限制设置为低于当前使用量或将软限制设置为高于现有硬限制将失败。 **-C **设置或显示核心文件限制。核心文件限制是进程允许的内存转储的最大大小(以 512 字节块为单位)。值 0(零)阻止创建文件。转储文件创建将在此限制处停止。 **-d **设置或显示数据大小限制。数据大小限制是进程中断值的最大大小,以 1024 字节为单位。此资源始终具有无限的硬限制和软限制。 **-F **设置或显示文件大小限制。文件大小限制是进程允许的最大文件大小(以 512 字节块为单位)。值 0(零)阻止创建文件。如果超出大小,则向进程发送 SIGXFSZ 信号。如果进程阻塞、捕获或忽略 SIGXFSZ,继续尝试将文件大小增加到超出限制将失败。 **-M **设置或显示允许进程分配和取消隐藏的 2 GB 以上的存储量,以兆字节为增量。尝试将存储大小限制设置为低于当前使用量或将软限制设置为高于现有硬限制将失败。 ulimit -M显示的存储量不一定反映在用户的 RACF® OMVS 段中找到的 MEMLIMIT 设置。显示的值取决于用户如何进入 OMVS shell 以及是否执行了身份更改。 **-n **设置或显示文件描述符限制。文件描述符限制是进程允许的打开文件描述符的最大数量。这个数字比可以分配给新创建的描述符的最大值大一。任何尝试创建超出限制的新文件描述符的函数都将失败。尝试将打开文件描述符限制设置为低于已使用的限制将失败。 **-s **设置或显示堆栈大小限制。堆栈大小限制是进程的最大堆栈大小,以 1024 字节为单位。堆栈是具有无限硬和软限制的每线程资源。 **-t **设置或显示 CPU 时间限制。CPU 时间限制是进程允许的最大 CPU 时间量(以秒为单位)。如果超出限制,则会向进程发送一个 SIGXCPU 信号,并授予该进程一个小的 CPU 时间扩展,以允许信号生成和传递。如果扩展名已用完,则进程以 SIGKILL 信号终止。尝试将 CPU 限制设置为低于已使用的限制将失败。 **num** 新的限制。num可以指定为“无限”。 #### 使用说明 1. ulimit是一个内置的 shell 命令。它不能与 tcsh shell 一起使用。 2. 如果由于尝试将资源限制设置为低于当前使用量或高于现有硬限制而导致命令失败,则生成的错误消息可能指示无效参数。 # 编译 [内核在线文档](https://www.kernel.org/doc/html/latest/index.html) [详细工具](http://book.321jr.com/books/33e75/page/1afa3) #### 本机信息 **操作系统** ``` uname -a #查看系统内核版本号及系统名称 uname --m #操作系统32位/64位 lsb_release -a #本机系统发行版本信息 ``` [![image-1659006313769.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/0sOzDPnoNVU3heLi-image-1659006313769.png)](http://book.321jr.com/uploads/images/gallery/2022-07/0sOzDPnoNVU3heLi-image-1659006313769.png) `Distributor ID:`Ubuntu 类别是ubuntu `Description:`Ubuntu 20.04.2 LTS 代表长时间支持版本 `Release:` 20.04 发行版本号 `Codename:`focal 是 ubuntu的代号名称 **系统内核** ``` uname --s #内核名字 uname --r #内核版本 uname --n #网络主机名 uname --p #cpu ```
**下载工具** ``` sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison ``` #### 准备内核 **下载内核**
``` wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-5.5.9.tar.xz ``` **解压内核** ``` tar xf linux-5.5.9.tar.xz ``` **进入解压后的内核文件夹中** ``` cd linux-5.5.9 ``` [![image-1659028706311.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/djSs4021bx1zEBX0-image-1659028706311.png)](http://book.321jr.com/uploads/images/gallery/2022-07/djSs4021bx1zEBX0-image-1659028706311.png) # 编译前言 ## 编译 - - - - - - 先简单说一下下载吧, 我是直接从 GitHub 上 Linux 的仓库直接下载的, 当然也可以去内核 的[官方网站](https://www.kernel.org/)上下载, 这上面不仅有最新稳定版本的内核,一些 历史版本的内核也可以从这里下载到。 不仅如此, Linux 的内核仓库中其实还包含了大量 的文档, 可以选择自己编译出内核文档,也可以使用 [在线文档](https://www.kernel.org/doc/html/latest/index.html)。 NOTE: 在线的文档可能更方便一点, 自己编译的话要在自己电脑上安装一些工具啥的。 现在进入正题: #### 配置内核 Linux 内核的配置方法有很多, 下面这三种应该是目前使用比较广泛的三种方式: ``` make menuconfig # Update current config utilising a menu based program make xconfig # Update current config utilising a Qt based front-end make gconfig # Update current config utilising a GTK+ based front-end ```
这三个命令在配置时只需要用一个就可以了, 命令后面的注释说明了这三个命令的使用条件。 这里先介绍一下 `make help` 命令。 这条命令可以查看到内核编译时所有 Make 可用的目标 及介绍, 上面的注释便出自这里。 我之前配置时也只用过第一种方法,这次编译我的电脑也支持 后面两个命令的条件,所以在这里我也展示一下这三种配置方式的界面。 - `make menuconfig` 配置界面 [![image-1659007242420.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/xugeF8Qdc9o4jNyJ-image-1659007242420.png)](http://book.321jr.com/uploads/images/gallery/2022-07/xugeF8Qdc9o4jNyJ-image-1659007242420.png) - `make xconfig` 配置界面 [![image-1659007294065.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/I4JmxHrvAXfo74HS-image-1659007294065.png)](http://book.321jr.com/uploads/images/gallery/2022-07/I4JmxHrvAXfo74HS-image-1659007294065.png) - `make gconfig` 的配置界面 [![image-1659007326913.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/g9Yjgc8gYkZFBYcB-image-1659007326913.png)](http://book.321jr.com/uploads/images/gallery/2022-07/g9Yjgc8gYkZFBYcB-image-1659007326913.png) 使用哪种方式可以说取决于个人喜好了或者自己电脑所具备的条件了,毕竟他们最终的目的 都是生成名为 `.config` 的内核配置文件。 在配置具体功能时最多有三种选择: - Y – 将该功能编译进内核 - N – 不要将该功能编译进内核 - M – 将该功能编译成模块 基本每个功能配置都会有对应的帮助说明, 非常的人性化。 需要注意的是这个步骤其实并 不是每次都必须的, 比如之前已经配置过了,或者从其他地方拷贝来了可用的配置文件, 这一步是完全可以跳过的。配置完成后就可以开始编译了。 #### 编译内核 开始编译时直接使用 `make` 命令即可。 当然如果想加快编译的速度, 可以追加 `-j` 参 数。 ``` make -j 4 # 同时运行 4 个作业,这里取值推荐为 2 倍的 CPU Core 数 make -j $(nproc) # 可以通过 nproc 命令得到可用处理单元的数量 ``` #### 编译模块 上面配置内核时说到有三种选择,配置时候选择 `M` 编译为模块的功能特性在这里可以用 下面的命令编译出来 ``` make modules ``` 至此,需要编译的代码都已经编译完成。 - - - - - - Linux 内核的 Makefile 还有很多目标 ``` make modules_install #安装内核模块 make htmldocs #生成 html 格式的内核文档 ``` .............. # 详细工具 ### 环境
在认为您遇到错误之前,至少升级到这些软件版本!如果您不确定当前运行的是什么版本,建议的命令应该会告诉您。同样,请记住,此列表假定您已经在功能上运行 Linux 内核。此外,并非所有系统都需要所有工具。显然,如果您没有任何 PC 卡硬件,例如,您可能不需要关心 pcmciautils。 务必注意:您将需要至少 200GB 的本地可用磁盘空间来完成内核的编译过程。
程序 最低版本 检查版本的命令
GNU C 5.1 gcc -v
Clang/LLVM (optional) 11.0.0 clang –version
GNU make 3.81 make –version
bash 4.2 bash –version
binutils 2.23 ld -v
flex 2.5.35 flex –version
bison 2.0 bison –version
pahole 1.16 pahole –version
util-linux 2.10o fdformat –version
kmod 13 depmod -V
e2fsprogs 1.41.4 e2fsck -V
jfsutils 1.1.3 fsck.jfs -V
reiserfsprogs 3.6.3 reiserfsck -V
xfsprogs 2.6.0 xfs\_db -V
squashfs-tools 4.0 mksquashfs -version
btrfs-progs 0.18 btrfsck
pcmciautils 004 pccardctl -V
quota-tools 3.09 quota -V
PPP 2.4.0 pppd –version
nfs-utils 1.0.5 showmount –version
procps 3.2.0 ps –version
udev 081 udevd –version
grub 0.93 grub –version || grub-install –version
mcelog 0.6 mcelog –version
iptables 1.4.2 iptables -V
openssl & libcrypto 1.0.0 openssl version
bc 1.06.95 bc –version
Sphinx[1](https://www.kernel.org/doc/html/latest/process/changes.html#f1) 1.7 sphinx-build –version
cpio any cpio –version
仅在构建内核文档时才需要 [Sphinx](https://www.kernel.org/doc/html/latest/process/changes.html#id1)
### 内核编译
#### GCC gcc 版本要求可能因计算机中 CPU 的类型而异。
#### Clang/LLVM (可选) 支持构建内核的最新正式[版本](https://releases.llvm.org/)的 clang 和 LLVM 实用程序(根据 release.llvm.org )。不保证旧版本可以正常工作,我们可能会从内核中删除用于支持旧版本的变通方法。请参阅有关[使用 Clang/LLVM 构建 Linux 的](https://www.kernel.org/doc/html/latest/kbuild/llvm.html#kbuild-llvm)其他文档。
#### Make 制作 您将需要 GNU make 3.81 或更高版本来构建内核。
#### Bash 一些 bash 脚本用于内核构建。需要 Bash 4.2 或更高版本。
#### Binutils 二进制工具 构建内核需要 Binutils 2.23 或更高版本。
#### pkg-config 包配置 从 4.18 开始,构建系统需要 pkg-config 来检查已安装的 kconfig 工具并确定在 ‘make {g,x}config’中使用的标志设置。以前 pkg-config 正在使用但未验证或记录。
#### Flex[¶](https://www.kernel.org/doc/html/latest/process/changes.html#flex "Permalink to this heading") 从 Linux 4.16 开始,构建系统在构建期间会生成词法分析器。这需要 flex 2.5.35 或更高版本。
#### Bison
从 Linux 4.16 开始,构建系统在构建期间生成解析器。这需要 bison 2.0 或更高版本。
#### pahole 从 Linux 5.2 开始,如果选择了 CONFIG\_DEBUG\_INFO\_BTF,则构建系统会从 vmlinux 中的 DWARF 生成 BTF(BPF 类型格式),稍后也会从内核模块生成 BTF(BPF 类型格式)。这需要 pahole v1.16 或更高版本。
它可以在 'dwarves' 或 'pahole' 发行包或 [https://fedorapeople.org/~acme/dwarves/](https://fedorapeople.org/~acme/dwarves/)中找到。
#### Perl 您将需要 perl 5 和以下模块: `Getopt::Long`, `Getopt::Std`, `File::Basename`, and `File::Find` 来构建内核。
#### BC
您将需要 bc 来构建内核 3.10 及更高版本
#### OpenSSL 模块签名和外部证书处理使用 OpenSSL 程序和加密库来创建密钥和生成签名。
如果启用了模块签名,您将需要 openssl 来构建 3.7 及更高版本的内核。您还需要 openssl 开发包来构建内核 4.3 及更高版本。
### 系统实用程序
#### 架构变化 DevFS 已经过时,取而代之的是 udev ( [https://www.kernel.org/pub/linux/utils/kernel/hotplug/](https://www.kernel.org/pub/linux/utils/kernel/hotplug/) ) 32 位 UID 支持现已到位。玩得开心!
函数的 Linux 文档正在通过靠近源代码定义的特殊格式的注释转换为内联文档。这些注释可以与文档/目录中的 ReST 文件相结合,以制作丰富的文档,然后可以将其转换为 PostScript、HTML、LaTex、ePUB 和 PDF 文件。为了从 ReST 格式转换为您选择的格式,您需要 Sphinx。
#### Util-linux 实用程序
新版本的 util-linux`fdisk`支持更大的磁盘,支持新的挂载选项,识别更多支持的分区类型,具有适用于 2.4 内核的 fdformat,以及类似的好东西。您可能想要升级。
#### Ksymoops 克西莫普斯
如果发生了不可想象的事情并且您的内核出现故障,您可能需要 ksymoops 工具对其进行解码,但在大多数情况下您不需要。通常首选构建内核,`CONFIG_KALLSYMS`以便它生成可以按原样使用的可读转储(这也产生比 ksymoops 更好的输出)。如果由于某种原因您的内核没有构建,`CONFIG_KALLSYMS`并且您无法使用该选项重建和重现 Oops,那么您仍然可以使用 ksymoops 解码该 Oops。
#### Mkinitrd
对文件树布局的这些更改`/lib/modules`还需要升级 mkinitrd。
#### E2fsprogs
最新版本`e2fsprogs`修复了 fsck 和 debugfs 中的几个错误。显然,升级是个好主意。
#### JFSutils 该`jfsutils`软件包包含文件系统的实用程序。可以使用以下实用程序: - `fsck.jfs` - 启动事务日志的重放,检查和修复 JFS 格式的分区。 - `mkfs.jfs` - 创建一个 JFS 格式的分区。 - 此软件包中还提供了其他文件系统实用程序。
#### Reiserfsprogs
reiserfsprogs 包应该用于 reiserfs-3.6.x(Linux 内核 2.4.x)。它是一个组合包,包含`mkreiserfs`、和 . 这些实用程序可在 i386 和 alpha 平台上运行。`resize_reiserfs``debugreiserfs``reiserfsck`
#### Xfsprogs
最新版本的`xfsprogs`contains `mkfs.xfs`、`xfs_db`和 `xfs_repair`实用程序等,用于 XFS 文件系统。它独立于体系结构,并且从 2.0.0 开始的任何版本都应该可以与此版本的 XFS 内核代码一起正常工作(建议使用 2.6.0 或更高版本,因为有一些重大改进)。
#### PCMCIAutils
PCMCIAutils 替换`pcmcia-cs`. 如果内核是模块化的并且使用了热插拔子系统,它会在系统启动时正确设置 PCMCIA 套接字并为 16 位 PCMCIA 设备加载适当的模块。
#### Quota-tools
如果要使用较新的版本 2 配额格式,则需要支持 32 位 uid 和 gid。Quota-tools 3.07 及更新版本具有此支持。使用上表中推荐的版本或更新版本。
#### Intel IA32 microcode 添加了一个驱动程序以允许更新英特尔 IA32 微码,可作为普通(杂项)字符设备访问。如果您不使用 udev,您可能需要:
``` mkdir /dev/cpu mknod /dev/cpu/microcode c 10 184 chmod 0644 /dev/cpu/microcode ```
以root身份使用它。您可能还希望使用用户空间 microcode\_ctl 实用程序来使用它。
#### udev
`udev``/dev`是一个用户空间应用程序,用于仅使用实际存在的设备的条目动态填充。`udev`替换了 devfs 的基本功能,同时允许对设备进行持久的设备命名。
#### FUSE
需要 libfuse 2.4.0 或更高版本。绝对最小值是 2.3.0,但挂载选项`direct_io`不起作用`kernel_cache`。
### Networking 联网
#### General changes 一般变化 如果您有高级网络配置需求,您可能应该考虑使用 ip-route2 中的网络工具。
#### Packet Filter / NAT 包过滤/NAT
包过滤和 NAT 代码使用与之前的 2.4.x 内核系列 (iptables) 相同的工具。它仍然包括 2.2.x 风格的 ipchains 和 2.0.x 风格的 ipfwadm 的向后兼容模块。
#### PPP PPP 驱动程序已经过重组,以支持多链路并使其能够在不同的媒体层上运行。如果您使用 PPP,请将 pppd 至少升级到 2.4.0。 如果您不使用 udev,则必须拥有设备文件 /dev/ppp,该文件可以通过以下方式制作:
``` mknod /dev/ppp c 108 0 ```
作为根。
#### NFS-utils 实用程序 在古老的(2.4 和更早的)内核中,nfs 服务器需要知道任何期望能够通过 NFS 访问文件的客户端。此信息将`mountd`在客户端安装文件系统时或`exportfs`系统启动时提供给内核。exportfs 将从`/var/lib/nfs/rmtab`. 这种方法非常脆弱,因为它取决于 rmtab 是否正确,这并不总是那么容易,尤其是在尝试实现故障转移时。即使系统运行良好,也会`rmtab`遭受到许多永远不会被删除的旧条目的困扰。 使用现代内核,我们可以选择让内核在收到来自未知主机的请求时告诉 mountd,而 mountd 可以向内核提供适当的导出信息。这消除了对内核的依赖`rmtab`,意味着内核只需要知道当前活动的客户端。 要启用此新功能,您需要:
``` mount -t nfsd nfsd /proc/fs/nfsd ```
在运行 exportfs 或 mountd 之前。建议在可能的情况下通过防火墙保护所有 NFS 服务免受 Internet 的影响。
#### mcelog
在 x86 内核上,启用时需要 mcelog 实用程序来处理和记录机器检查事件`CONFIG_X86_MCE`。机器检查事件是 CPU 报告的错误。强烈建议处理它们。
### Kernel documentation 内核文档
#### Sphinx 狮身人面像
有关 Sphinx 要求的详细信息,请参阅[Documentation/doc-guide/sphinx.rst](https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html#sphinxdoc)中的[Sphinx 安装。](https://www.kernel.org/doc/html/latest/doc-guide/sphinx.html#sphinx-install)
## Getting updated software 获取更新的软件
### Kernel compilation 内核编译
#### gcc - <[ftp://ftp.gnu.org/gnu/gcc/](ftp://ftp.gnu.org/gnu/gcc/)>
#### Clang/LLVM - [Getting LLVM](https://www.kernel.org/doc/html/latest/kbuild/llvm.html#getting-llvm).
#### Make - <[ftp://ftp.gnu.org/gnu/make/](ftp://ftp.gnu.org/gnu/make/)>
#### Bash - <[ftp://ftp.gnu.org/gnu/bash/](ftp://ftp.gnu.org/gnu/bash/)>
#### Binutils - <[https://www.kernel.org/pub/linux/devel/binutils/](https://www.kernel.org/pub/linux/devel/binutils/)>
#### Flex - <[https://github.com/westes/flex/releases](https://github.com/westes/flex/releases)>
#### Bison - <[ftp://ftp.gnu.org/gnu/bison/](ftp://ftp.gnu.org/gnu/bison/)>
#### OpenSSL - <[https://www.openssl.org/](https://www.openssl.org/)>
### System utilities
#### Util-linux - <[https://www.kernel.org/pub/linux/utils/util-linux/](https://www.kernel.org/pub/linux/utils/util-linux/)>
#### Kmod - <[https://www.kernel.org/pub/linux/utils/kernel/kmod/](https://www.kernel.org/pub/linux/utils/kernel/kmod/)> - <[https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git](https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git)>
#### Ksymoops - <[https://www.kernel.org/pub/linux/utils/kernel/ksymoops/v2.4/](https://www.kernel.org/pub/linux/utils/kernel/ksymoops/v2.4/)>
#### Mkinitrd - <[https://code.launchpad.net/initrd-tools/main](https://code.launchpad.net/initrd-tools/main)>
#### E2fsprogs - <[https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/](https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/)> - <[https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/](https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/)>
#### JFSutils - <[http://jfs.sourceforge.net/](http://jfs.sourceforge.net/)>
#### Reiserfsprogs - <[https://git.kernel.org/pub/scm/linux/kernel/git/jeffm/reiserfsprogs.git/](https://git.kernel.org/pub/scm/linux/kernel/git/jeffm/reiserfsprogs.git/)>
#### Xfsprogs - <[https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git](https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git)> - <[https://www.kernel.org/pub/linux/utils/fs/xfs/xfsprogs/](https://www.kernel.org/pub/linux/utils/fs/xfs/xfsprogs/)>
#### Pcmciautils - <[https://www.kernel.org/pub/linux/utils/kernel/pcmcia/](https://www.kernel.org/pub/linux/utils/kernel/pcmcia/)>
#### Quota-tools - <[http://sourceforge.net/projects/linuxquota/](http://sourceforge.net/projects/linuxquota/)>
#### Intel P6 microcode - <[https://downloadcenter.intel.com/](https://downloadcenter.intel.com/)>
#### udev - <[https://www.freedesktop.org/software/systemd/man/udev.html](https://www.freedesktop.org/software/systemd/man/udev.html)>
#### FUSE - <[https://github.com/libfuse/libfuse/releases](https://github.com/libfuse/libfuse/releases)>
#### mcelog - <[http://www.mcelog.org/](http://www.mcelog.org/)>
#### cpio - <[https://www.gnu.org/software/cpio/](https://www.gnu.org/software/cpio/)>
### Networking
#### PPP - <[https://download.samba.org/pub/ppp/](https://download.samba.org/pub/ppp/)> - <[https://git.ozlabs.org/?p=ppp.git](https://git.ozlabs.org/?p=ppp.git)> - <[https://github.com/paulusmack/ppp/](https://github.com/paulusmack/ppp/)>
#### NFS-utils - <[http://sourceforge.net/project/showfiles.php?group\_id=14](http://sourceforge.net/project/showfiles.php?group_id=14)>
#### Iptables - <[https://netfilter.org/projects/iptables/index.html](https://netfilter.org/projects/iptables/index.html)>
#### Ip-route2 - <[https://www.kernel.org/pub/linux/utils/net/iproute2/](https://www.kernel.org/pub/linux/utils/net/iproute2/)>
#### OProfile - <[http://oprofile.sf.net/download/](http://oprofile.sf.net/download/)>
#### NFS-Utils - <[http://nfs.sourceforge.net/](http://nfs.sourceforge.net/)>
### Kernel documentation
#### Sphinx - <[https://www.sphinx-doc.org/](https://www.sphinx-doc.org/)>
# 内核的作用 内核有 4 项工作: 1. **内存管理:**追踪记录有多少内存存储了什么以及存储在哪里 2. **进程管理:**确定哪些进程可以使用中央处理器(CPU)、何时使用以及持续多长时间 3. **设备驱动程序:**充当硬件与进程之间的调解程序/解释程序 4. **系统调用和安全防护:**从流程接受服务请求 在正确实施的情况下,内核对于用户是不可见的,它在自己的小世界(称为内核空间)中工作,并从中分配内存和跟踪所有内容的存储位置。用户所看到的内容(例如 Web 浏览器和[文件](https://www.redhat.com/zh/topics/data-storage/file-block-object-storage))则被称为用户空间。这些应用通过系统调用接口(SCI)与内核进行交互。 *举例来说,*内核就像是一个为高管(硬件)服务的忙碌的个人助理。助理的工作就是将员工和公众(用户)的消息和请求(进程)转交给高管,记住存放的内容和位置(内存),并确定在任何特定的时间谁可以拜访高管、会面时间有多长。 # 系统 安装 配置 导入 备份 # 从零开始的 Linux ## Linux From Scratch (简体中文版) # 软件 1、软件:软件包+依赖包+配置文件,已安装后的文件; 2、命令:查找,下载,安装,更新,卸载,删除; 3、地址:仓库地址,下载目录,安装目录; # rp-pppoe #### 配置 - /rp-pppoe/configs/pppoe.conf - 69行 CONNECT\_TIMEOUT=0 [![image-1659023223460.png](http://book.321jr.com/uploads/images/gallery/2022-07/scaled-1680-/6wBnTG30HmgGRxOT-image-1659023223460.png)](http://book.321jr.com/uploads/images/gallery/2022-07/6wBnTG30HmgGRxOT-image-1659023223460.png) ``` #*********************************************************************** # # pppoe.conf # # Configuration file for rp-pppoe. Edit as appropriate and install in # /etc/ppp/pppoe.conf # # NOTE: This file is used by the pppoe-start, pppoe-stop, pppoe-connect and # pppoe-status shell scripts. It is *not* used in any way by the # "pppoe" executable. # # Copyright (C) 2000 Roaring Penguin Software Inc. # # This file may be distributed under the terms of the GNU General # Public License. # # LIC: GPL # $Id$ #*********************************************************************** # When you configure a variable, DO NOT leave spaces around the "=" sign. # Ethernet card connected to DSL modem ETH=eth0 # PPPoE user name. You may have to supply "@provider.com" Sympatico # users in Canada do need to include "@sympatico.ca" # Sympatico uses PAP authentication. Make sure /etc/ppp/pap-secrets # contains the right username/password combination. # For Magma, use xxyyzz@magma.ca USER=02368109376 # Bring link up on demand? Default is to leave link up all the time. # If you want the link to come up on demand, set DEMAND to a number indicating # the idle time after which the link is brought down. DEMAND=no #DEMAND=300 # DNS type: SERVER=obtain from server; SPECIFY=use DNS1 and DNS2; # NOCHANGE=do not adjust. DNSTYPE=SERVER # Obtain DNS server addresses from the peer (recent versions of pppd only) # In old config files, this used to be called USEPEERDNS. Changed to # PEERDNS for better Red Hat compatibility PEERDNS=no DNS1= DNS2= # Make the PPPoE connection your default route. Set to # DEFAULTROUTE=no if you don't want this. DEFAULTROUTE=no ### ONLY TOUCH THE FOLLOWING SETTINGS IF YOU'RE AN EXPERT # How long pppoe-start waits for a new PPP interface to appear before # concluding something went wrong. If you use 0, then pppoe-start # exits immediately with a successful status and does not wait for the # link to come up. Time is in seconds. # # WARNING WARNING WARNING: # # If you are using rp-pppoe on a physically-inaccessible host, set # CONNECT_TIMEOUT to 0. This makes SURE that the machine keeps trying # to connect forever after pppoe-start is called. Otherwise, it will # give out after CONNECT_TIMEOUT seconds and will not attempt to # connect again, making it impossible to reach. CONNECT_TIMEOUT=30 # How often in seconds pppoe-start polls to check if link is up CONNECT_POLL=2 # Specific desired AC Name ACNAME= # Specific desired service name SERVICENAME= # Character to echo at each poll. Use PING="" if you don't want # anything echoed PING="." # File where the pppoe-connect script writes its process-ID. # Three files are actually used: # $PIDFILE contains PID of pppoe-connect script # $PIDFILE.pppoe contains PID of pppoe process # $PIDFILE.pppd contains PID of pppd process CF_BASE=`basename $CONFIG` PIDFILE="/var/run/$CF_BASE-pppoe.pid" # Do you want to use synchronous PPP? "yes" or "no". "yes" is much # easier on CPU usage, but may not work for you. It is safer to use # "no", but you may want to experiment with "yes". "yes" is generally # safe on Linux machines with the n_hdlc line discipline; unsafe on others. SYNCHRONOUS=no # Do you want to clamp the MSS? Here's how to decide: # - If you have only a SINGLE computer connected to the DSL modem, choose # "no". # - If you have a computer acting as a gateway for a LAN, choose "1412". # The setting of 1412 is safe for either setup, but uses slightly more # CPU power. CLAMPMSS=1412 #CLAMPMSS=no # LCP echo interval and failure count. LCP_INTERVAL=20 LCP_FAILURE=3 # PPPOE_TIMEOUT should be about 4*LCP_INTERVAL PPPOE_TIMEOUT=80 # Firewalling: One of NONE, STANDALONE or MASQUERADE FIREWALL=NONE # Linux kernel-mode plugin for pppd. If you want to try the kernel-mode # plugin, use LINUX_PLUGIN=/etc/ppp/plugins/rp-pppoe.so LINUX_PLUGIN= # Any extra arguments to pass to pppoe. Normally, use a blank string # like this: PPPOE_EXTRA="" # Rumour has it that "Citizen's Communications" with a 3Com # HomeConnect DSL Modem DualLink requires these extra options: # PPPOE_EXTRA="-f 3c12:3c13 -S ISP" # Any extra arguments to pass to pppd. Normally, use a blank string # like this: PPPD_EXTRA="" ########## DON'T CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING # If you wish to COMPLETELY overrride the pppd invocation: # Example: # OVERRIDE_PPPD_COMMAND="pppd call dsl" # If you want pppoe-connect to exit when connection drops: # RETRY_ON_FAILURE=no ```