常见场景

内核默认启动版本管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## 方法1
# 查看当前默认启动内核
[root@k104 ~]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)

# 查看所有可用内核
[root@k104 ~]# cat /boot/grub2/grub.cfg | grep ^menuentry
menuentry 'CentOS Linux (5.4.134-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-5.4.134-1.el7.elrepo.x86_64-advanced-f7d63930-b583-4731-976f-29c94ff7bdd6' {
menuentry 'CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-1127.el7.x86_64-advanced-f7d63930-b583-4731-976f-29c94ff7bdd6' {
menuentry 'CentOS Linux (0-rescue-3144d2251e4742d79fe35eb04ed8eba2) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-3144d2251e4742d79fe35eb04ed8eba2-advanced-f7d63930-b583-4731-976f-29c94ff7bdd6' {

# 修改默认启动内核
[root@k104 ~]# grub2-set-default 'CentOS Linux (3.10.0-1127.el7.x86_64) 7 (Core)'

# 查看系统当前内核
[root@k104 ~]# uname -a
Linux k104 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


## 方法2
#查看当前默认内核:
[root@k104 ~]# grubby --default-kernel

#查看当前已安装内核:
[root@k104 ~]# ls /boot/vmlinuz*

#默认内核设置为要切换的内核
[root@k104 ~]# grubby --set-default=/boot/vmlinuz-3.10.0-1127.el7.x86_64

#重启
[root@k104 ~]# reboot

#查看内核切换成功
[root@k104 ~]# uname -r

IPv6管理

1
2
3
4
5
6
7
8
9
10
11
# 设置ipv6 ip
ip -6 addr add 2018::10/64 dev eth0

# 设置ipv6静态路由
ip -6 route add 2019::/64 via 2018::1 dev eth0

# 设置默认网关
route add default gw 192.168.0.1

# 查看ipv6路由表
ip -6 route show

tar.gz 压缩拆分

1
2
3
4
5
6
7
8
# 压缩拆分
tar zcvf - k8s_install/ | split -b 3G - iECI_v210430.tar.gz.
# PS:
# split -b 指定拆分小包的大小
# 生成iECI_v210430.tar.gz.开头,aa、ab、ac...等小包

# 解压拆分
cat iECI_v210430.tar.gz.* | tar zxv

搭建本地ISO yum源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 挂载ISO文件
mount -o loop /root/CentOS-7-x86_64-Everything-2009.iso /mnt/cdrom/
cat >> /etc/fstab << EOF
/root/CentOS-7-x86_64-Everything-2009.iso /mnt/cdrom/ iso9660 loop,defaults 0 0
EOF

# 更新yum源文件
cd /etc/yum.repos.d/ && mkdir bak && mv * bak
cat > /etc/yum.repos.d/local.repo << EOF
[local]
name=local
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=0
EOF

# 更新yum源缓存
yum clean all && yum makecache

Selinux修改服务端口

1
2
3
4
5
# 查看ssh服务端口
semanage port -l |grep ssh

# 添加ssh新端口
semanage port -a -t ssh_port_t -p tcp 2202

Firewalld基础管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查看状态
firewall-cmd --state

# 查看所有打开的端口
firewall-cmd --zone=public --list-ports

# 添加开放端口
firewall-cmd --zone=public --add-port=2202/tcp --permanent

# 移除开放端口
firewall-cmd --zone=public --remove-port=2202/tcp --permanent

# 重新加载规则
firewall-cmd --reload

# 查看端口是否开放
firewall-cmd --zone=public --query-port=2202/tcp