Skip to content

Commit feccba6

Browse files
authored
Dev xbl/feature update centos kernel (#132)
* update-kernel * update-kernel * update-kernel * update-kernel * update-kernel * update-kernel * update-kernel * update-kernel --------- Co-authored-by: xubiaolin <xubiaolin>
1 parent 29864ea commit feccba6

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

deploy.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
11
#!/bin/bash
22
CONTAINER_NAME=myztplanet
33

4+
# 如果是centos 且内核版本小于5.*,提示内核版本太低
5+
kernel_check(){
6+
os_name=$(cat /etc/os-release | grep ^ID= | cut -d'=' -f2)
7+
kernel_version=$(uname -r | cut -d'.' -f1)
8+
if [[ "$kernel_version" -lt 5 ]]; then
9+
if [[ "$os_name" == "\"centos\"" ]]; then
10+
echo -e "\033[31m内核版本太低,请在菜单中选择CentOS内核升级\033[0m"
11+
exit 1
12+
else
13+
echo -e "\033[31m请自行升级系统内核到5.*及其以上版本\033[0m"
14+
exit 1
15+
fi
16+
else
17+
echo "当前内核版本为:$kernel_version"
18+
echo -e "\033[32m系统和内核版本检查通过。\033[0m"
19+
fi
20+
}
21+
22+
update_centos_kernal(){
23+
echo "请注意备份数据,升级内核有风险"
24+
read -p "是否继续升级内核?(y/n)" continue_update
25+
continue_update=${continue_update:-n}
26+
if [[ "$continue_update" =~ ^[Yy]$ ]]; then
27+
echo "如果配置较低,可能升级时间较长,请耐心等待!开始升级内核..."
28+
yum update -y
29+
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
30+
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm -y
31+
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
32+
yum --enablerepo=elrepo-kernel install kernel-lt-devel kernel-lt -y
33+
sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
34+
grub2-set-default 0
35+
grub2-mkconfig -o /boot/grub2/grub.cfg
36+
37+
read -p "内核升级完成,请重启系统,是否立刻重启?(y/n)" reboot
38+
reboot=${reboot:-n}
39+
if [[ "$reboot" =~ ^[Yy]$ ]]; then
40+
reboot now
41+
else
42+
echo "已取消重启"
43+
exit 0
44+
fi
45+
46+
echo "内核升级完成,请重启系统"
47+
exit 0
48+
else
49+
echo "已取消升级内核"
50+
exit 0
51+
fi
52+
53+
}
54+
455
install_lsof() {
556
if [ ! -f "/usr/bin/lsof" ]; then
657
echo "开始安装lsof工具..."
@@ -32,6 +83,8 @@ read_port() {
3283
}
3384

3485
install() {
86+
kernel_check
87+
3588
echo "开始安装,如果你已经安装了,将会删除旧的数据,10s后开始安装..."
3689
sleep 10
3790

@@ -261,6 +314,7 @@ menu() {
261314
# echo "3. 更新"
262315
echo "4. 查看信息"
263316
echo "5. 重置密码"
317+
echo "6. CentOS内核升级"
264318
echo "0. 退出"
265319
read -p "请输入数字:" num
266320
case "$num" in
@@ -269,6 +323,7 @@ menu() {
269323
# [3]) update ;;
270324
[4]) info ;;
271325
[5]) resetpwd ;;
326+
[6]) update_centos_kernal ;;
272327
[0]) exit ;;
273328
*) echo "请输入正确数字 [1-5]" ;;
274329
esac

0 commit comments

Comments
 (0)