2.2. Linux Kernel

kernel是操作系统的核心,掌控着所有硬件设备的控制权。

linux系统是单内核,模块化体系。

2.2.1. uname的使用

[root@centos6 ~]$ uname -a
Linux centos6.linuxpanda.tech 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[root@centos6 ~]$ uname -r
2.6.32-696.el6.x86_64
[root@centos6 ~]$ uname -n
centos6.linuxpanda.tech

2.2.2. 内核模块管理

2.2.2.1. 查看模块

# 方法1:
[root@centos6 ~]$ lsmod
Module                  Size  Used by
rfcomm                 71047  4
sco                    17493  2
bridge                 85706  0
bnep                   16370  2
l2cap                  54210  16 rfcomm,bnep
autofs4                27000  3
bnx2fc                 91541  0
#############省去下面的行#################

# 方法2
[root@centos6 ~]$ cat /proc/modules
rfcomm 71047 4 - Live 0xffffffffa0676000
sco 17493 2 - Live 0xffffffffa066c000
bridge 85706 0 - Live 0xffffffffa064e000
bnep 16370 2 - Live 0xffffffffa0646000

# 方法3
[root@centos6 ~]$ modinfo e1000
filename:       /lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net/e1000/e1000.ko
version:        7.3.21-k8-NAPI
license:        GPL

2.2.2.2. 装载模块

[root@centos6 ~]$ insmod /lib/modules/2.6.32-696.el6.x86_64/kernel/net/bluetooth/bluetooth.ko
[root@centos6 ~]$ modprobe  bluetooth

2.2.2.3. 卸载模块

[root@centos6 ~]$ rmmod /lib/modules/2.6.32-696.el6.x86_64/kernel/net/bluetooth/bluetooth.ko
[root@centos6 ~]$ modprobe -r bluetooth

2.2.3. 内核参数

修改内核参数

# 方法1
[root@centos6 ~]$ echo "1" > /proc/sys/net/ipv4/ip_forward
# 方法2
[root@centos6 ~]$ sysctl -w  net.ipv4.ip_forward=1
net.ipv4.ip_forward = 1
# 方法3
[root@centos6 ~]$ vim /etc/sysctl.conf
[root@centos6 ~]$ sysctl -p

2.2.4. 编译内核

参考

编译内核的情况:

  • 有新的功能需求,如支持虚拟化

  • 原来的内核太过臃肿

  • 升级来提高稳定性

  • 个人定制或专业用途

  • 个人学习

编译内核的步骤

  1. 查看硬件设备信息

  2. 开发环境和源码

  3. 下载并解压源码

  4. 复制系统的默认的编译配置

  5. make menconfig

  6. make -j 4

  7. make modules_install

  8. make install

2.2.5. screen命令

screen可以让执行的命令脱离终端和终端无关。

选项:

-d

将指定的screen作业离线

-r

恢复指定的作业

-S

创建一个作业

-ls

查看作业

使用样例:

# 创建一个test名字的
[root@centos-155 ~]# screen -S test
[detached from 14681.test]
# 使用ctrl + a +d 来离线

# 查看作业
[root@centos-155 ~]# screen -ls
There is a screen on:
    14681.test      (Detached)
1 Socket in /var/run/screen/S-root.
# 恢复特定的作业
[root@centos-155 ~]# screen -r test