适用于云服务器,远程安装纯净版的CentOS7.9

脚本执行完成后使用VNC客户端连接

一键重装脚本

#!/bin/bash
#Net Reinstall Centos System red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
nicCard=$(ls /sys/class/net)
nicCard=(${nicCard})
d0Str='$0'
nicCardName=""
vnc_password=""
repo_url=""
ipaddr=""
gateway=""
netmask=""
bootRoot="" run_script() {
if [ -f "/boot/initrd79.img" ]; then
rm -rf /boot/initrd79.img
fi
wget -P /boot/ ${repo_url}images/pxeboot/initrd.img -O /boot/initrd79.img >/dev/null
if [ -f "/boot/vmlinuz79" ]; then
rm -rf /boot/vmlinuz79
fi
wget -P /boot/ ${repo_url}images/pxeboot/vmlinuz -O /boot/vmlinuz79 >/dev/null
startDiskPart=$(cat /boot/grub2/grub.cfg | grep "set root" | head -n 1 | awk -F \' '{print $2}')
startDiskType=$(df -T /boot | awk '{print $2}' | sed -n '2p')
if [ "ext4" = "${startDiskType}" -o "ext3" = "${startDiskType}" ]; then
startDiskType="ext2"
fi
cat <<EOF >/etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 ${d0Str}
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'NetInstall' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod ${startDiskType}
set root='${startDiskPart}' linux16 ${bootRoot}/vmlinuz79 inst.vnc inst.vncpassword=${vnc_password} inst.headless ip=${ipaddr}::${gateway}:${netmask}::${nicCardName}:none nameserver=223.5.5.5 inst.repo=${repo_url} inst.lang=en_US inst.keymap=us
initrd16 ${bootRoot}/initrd79.img
}
EOF
if [ -f "/boot/efi/EFI/centos/grub.cfg" ]; then
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
fi
if [ -f "/boot/grub2/grub.cfg" ]; then
grub2-mkconfig -o /boot/grub2/grub.cfg
fi
#awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
#grub2-editenv list
grub2-reboot NetInstall
sleep 10
reboot
} input_nic() {
bootRoot=$(cat /boot/grub2/grub.cfg | grep "linux16" | head -n 1)
bootRoot=${bootRoot#*/}
bootRoot=${bootRoot:0:4}
if [ "boot" = "${bootRoot}" ]; then
bootRoot="/boot"
else
bootRoot=""
fi
while true; do
for ((i = 1; i <= ${#nicCard[@]}; i++)); do
local_p="${nicCard[$i - 1]}"
echo -e "${green}${i}${plain}) ${local_p}"
done
read -p "请输入主网卡序号[默认 1]:" input_nic_no
[ -z "$input_nic_no" ] && input_nic_no=1
expr ${input_nic_no} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo -e "[${red}错误:${plain}] 请输入一个数字"
continue
fi
if [[ "$input_nic_no" -lt 1 || "$input_nic_no" -gt ${#nicCard[@]} ]]; then
echo -e "[${red}错误:${plain}] 请输入一个数字 1 - ${#nicCard[@]}"
continue
fi
nicCardName=${nicCard[$input_nic_no - 1]}
break
done
read -p "请输入 VNC 密码[6 位+][默认密码 tg_jockerli]:" input_passwd
[ -z "${input_passwd}" ] && input_passwd="tg_jockerli"
vnc_password=${input_passwd}
read -p "请输入 repo 地址[建议使用默认直接回车]:" input_repo
[ -z "${input_repo}" ] && input_repo="http://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/"
repo_url=${input_repo}
gateway=$(route -n | grep ${nicCardName} | grep UG | awk '{print $2}')
ipaddr=$(ifconfig ${nicCardName} | grep "inet" | awk -F " " '{print $2}' | head -n 1)
netmask=$(ifconfig ${nicCardName} | grep "inet" | awk -F " " '{print $4}' | head -n 1)
#ipaddr=$(ip route get 1 | awk '{print $NF;exit}')
#netmask=$(ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}' | head -1 | awk -F '/' '{print $2}')
#gateway=$(ip route | grep default | awk '{print $3}')
echo
echo "---------------------------"
echo -e "${green}网 卡 ${plain}= ${green}${nicCardName}${plain}"
echo -e "${green}IP 地址 ${plain}= ${green}${ipaddr}${plain}"
echo -e "${green}网 关 ${plain}= ${green}${gateway}${plain}"
echo -e "${green}掩 码 ${plain}= ${green}${netmask}${plain}"
echo "---------------------------"
echo -e "${green}VNC URL ${plain}= ${green}${ipaddr}:1${plain}"
echo "---------------------------"
echo -e "${green}VNC 密码 ${plain}= ${green}${vnc_password}${plain}"
echo -e "${yellow}VNC 密码确保在 6 位以上!并且不包含特殊字符!${plain}"
echo "---------------------------"
echo -e "${green}repo 地址 ${plain}= ${green}${repo_url}${plain}"
echo "---------------------------"
echo -e "注意:${yellow}VNC 只能在脚本运行完等待数分钟可用${plain}"
echo -e " ${yellow}请确保服务商防火墙端口[1]为开放状态${plain}"
echo
read -p "回车开始运行脚本;ctrl + c 取消本次操作" input_read
run_script
} init() {
if [ ! -f "/usr/bin/wget" ]; then
yum -y install wget >/dev/null
fi
if [ ! -f "/usr/sbin/ifconfig" ]; then
yum -y install net-tools >/dev/null
fi
input_nic
}
init

参考文档:

https://www.yunloc.com/1061.html

https://www.cnblogs.com/gleaners/p/5736521.html

http://www.danpros.com/2016/02/how-to-install-centos-7-remotely-using-vnc

VNC远程重装CentOS7的更多相关文章

  1. 使用vnc远程操控Centos7.6

    安装vncserver [root@elegant-snap-3 ~]# yum install tigervnc-server -y Loaded plugins: fastestmirror De ...

  2. (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)

    在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机 前提:服务器端安装桌面版的centos系统 CentOS Linux release 7.5.1804 (Core) ...

  3. Centos7 VNC远程桌面服务安装配置

    1.服务器版本 CentOS Linux release 7.7.1908 (Core) 首先系统安装了GUI界面 # ln -sf /lib/systemd/system/graphical.tar ...

  4. CentOS在ssh下远程重装系统

    CentOS在ssh下远程重装系统 http://www.zxsdw.com/index.php/archives/913/ 国外VPS服务器一般都有控制面板,有很多种系统可自行安装,但国内有些IDC ...

  5. 独立服务器远程重装Linux系统

    独立服务器远程重装Linux系统 http://rashost.com/blog/remote-reinstall-linux-dedicated-server 本文介绍怎样在没有console连接, ...

  6. 使用VNC远程linux机器

    一,在Windows机器上下载vnc客户端 vnc viewer是一款vnc远程客户端,可以很方便的从Windows机器远程安装了图形界面和vnc服务器的linux机器. 从官网下载https://w ...

  7. 记一次VNC远程连接Linux问题解决记录(5900端口测试、KDE桌面安装)

    最近几天,到一个项目上安装Linux部署环境.由于服务器在机房,而进机房又比较麻烦,于是选择VNC远程连接Linux就显得自然而然了.以前也用过VNC,而且还经常使用,由于各个项目环境不太一样,这次也 ...

  8. 使用VNC远程连接Windows Azure Linux虚拟机

    本文以Oracle Linux 6.4虚拟机为示例 一. 安装 tigervnc-server 使用“rpm -qa vnc”指令查看是否安装vnc服务,如果没有安装,则可以使用yum或者rpm进行安 ...

  9. vnc远程linux服务器黑屏

    本来想尝试用vnc连接到linux服务器上,图形化操作一点东西,不过遇到了困难,记录方便查询. 1,打开vnc 选择Ip和端口,连接上去显示黑屏. 2,于是想到系统原先没有安装图像化桌面.so,  y ...

随机推荐

  1. SQL 清除数据库日志

    exec sp_detach_db 'MCS4WLSQM','true' --运行上一个命令. --改名LOG文件后再关闭上一行代码,然后再运行下一行代码 exec sp_attach_single_ ...

  2. 跟我一起学Go系列:Go gRPC 安全认证方式-Token和自定义认证

    Go gRPC 系列: 跟我一起学Go系列:gRPC安全认证机制-SSL/TLS认证 跟我一起学 Go 系列:gRPC 拦截器使用 跟我一起学 Go 系列:gRPC 入门必备 接上一篇继续讲 gRPC ...

  3. Java中有趣的移位操作!彻底弄懂各个移位操作符的使用方式

    << <<: 左移运算,左移几位就补几个0 >> >>: 右移运算,为算术右移 如果数字为正数时,移位后在前面补0 如果数字为负数时,移位后在前面补1 ...

  4. spring、springmvc、springboot、springcloud的联系与区别

    spring和springMvc: 1. spring是一个一站式的轻量级的java开发框架,核心是控制反转(IOC)和面向切面(AOP),针对于开发的WEB层(springMvc).业务层(Ioc) ...

  5. java基础---集合(2)

    一. Set 集合 java.util.Set集合是Collection集合的子集合,与List集合平级.该集合中元素没有先后放入次序,且不允许重复. 存储的数据在底层数组中并非按照数组索引的顺序添加 ...

  6. spring中如何向一个单例bean中注入非单例bean

    看到这个题目相信很多小伙伴都是懵懵的,平时我们的做法大都是下面的操作 @Component public class People{ @Autowired private Man man; } 这里如 ...

  7. 公钥-私钥 白名单-黑名单 Linux 远程访问及控制(SSH)

    远程访问及控制一.SSH远程管理二.OpenSSH服务器① SSH (Secure Shell)协议② OpenSSH三.配置OpenSSH服务器举例四.sshd 服务支持两种验证方式五.使用SSH客 ...

  8. Linux常用命令 day day up

    一.Shell二.Linux命令的分类1.查看内部命令2.禁用内部命令三.Linux命令行格式四.编辑Linux命令行的辅助操作五.获得命令帮助的方法1.pwd--查看当前的工作目录2.cd--切换工 ...

  9. PYTHON PIP 快速安装

    清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https: ...

  10. C语言:键盘输入

    C语言有多个函数可以从键盘获得用户输入,它们分别是: scanf():和 printf() 类似,scanf() 可以输入多种类型的数据. getchar().getche().getch():这三个 ...