当前位置: 首页 > news >正文

Linux操作系统母盘便捷持久化部署方案

Linux操作系统母盘便捷持久化部署

以RHEL 7.9与RHEL 9.3为例:

1.系统安装部署重要部分

以下创建虚拟机部分大体上使用的RHEL 9.3 进行介绍(都是建议配置信息,根据自己电脑性能来定)

image-20251031092240080 image-20251031092355131 image-20251031094024516 image-20251031092718348 image-20251031092905019 image-20251031093019776 image-20251031093350160 image-20251031093445091 image-20251031095117990 image-20251031095255589 image-20251031095423806 image-20251031095519976 image-20251031095822787 image-20251031095902048 image-20251031100158051 image-20251031100235813 img
# 红帽7不建议将网卡配置文件打开
# 打开的话,记得删除网卡配置文件
image-20251031100621420 image-20251031101748484

第一次登录可能登录到普通用户,Logout之后,使用root用户登录即可

2 检查是否允许SSH远程登录

[root@localhost ~]# vim /etc/ssh/sshd_config
PermitRootLogin yes[root@localhost ~]# systemctl restart sshd
[root@localhost ~]# systemctl enable --now sshd
# 如果没有显示为yes,将其1改为yes即可 --> 链接远程登录工具

3.配置本地仓库

3.1 RHEL-9

1.在vmware中加载系统镜像,并设定虚拟光驱开机启动
如下图1所示:2.挂载光驱到系统目录
[root@RHEL-9 ~]# mkdir /local
[root@RHEL-9 ~]# mount /dev/cdrom /local3.设置光驱开机自动挂载
[root@RHEL-9 ~]# vim /etc/rc.d/rc.local         # 添加一条开机自运行脚本(就是把 mount /dev/cdrom /rhel9.3 命令添加一行即可!)[root@RHEL-9 ~]# more /etc/rc.d/rc.local        # 查看是否增添
mount /dev/cdrom  /local[root@RHEL-9 ~]# chmod +x /etc/rc.d/rc.local    # 加执行权限4.配置仓库
[root@rhel-9 ~]# cd /etc/yum.repos.d/
[root@rhel-9 yum.repos.d]# vim /etc/yum.repos.d/local.repo
[AppStream]
name=AppStream
baseurl=file:///local/AppStream
gpgcheck=1      # 这里也可以填写为0,后面也就可以不用加了,AppStream 下面同理
gpgkey=file:///local/RPM-GPG-KEY-redhat-release
enabled=1[BaseOS]
name=BaseOS
baseurl=file:///local/BaseOS
gpgcheck=1
gpgkey=file:///local/RPM-GPG-KEY-redhat-release
enabled=15.测试
[root@RHEL-9 yum.repos.d]# dnf search nginx     # 测试本地仓库是否成功

image-20250709145907562

3.2 RHEL-7

# 同理知:rhel-7的配置与步骤大差不差
root@localhost yum.repos.d]# vim rhel7.repo     # 下面写的太简陋了,但是也是可以的,还是推荐上面的写法
[local]
name = local
baseurl = file:///local
gpgcheck = 0root@localhost yum.repos.d]# yum list httpd     # 测试本地仓库是否成功

4.编写自动化配置脚本vmset.sh

4.1 RHEL-9

[root@rhel-9 ~]# vim /usr/bin/vmset.sh
#!/bin/bash
ifconfig $1 &> /dev/null || {echo "net device $1 is not exist"exit
}ping -c1 -w1 $2 &> /dev/null && {echo "$2 is exist"exit
}grep $1 -r /etc/NetworkManager/system-connections/ | awk -F : '{system("rm -rf " $1)}'cat >/etc/NetworkManager/system-connections/$1.nmconnection <<EOF
[connection]
id=$1
type=ethernet
interface-name=$1[ipv4]
address1=$2/24,172.25.254.2
dns=114.114.114.114;
method=manual
EOFchmod 600 /etc/NetworkManager/system-connections/$1.nmconnection
nmcli connection reload
nmcli connection up $1hostnamectl hostname $3grep -e "$2\t$3" /etc/hosts || {echo -e "$2\t$3"  >> /etc/hosts
}[root@rhel-9 ~]# chmod +x /usr/bin/vmset.sh# 编写之前可以将原有的网卡配置文件删除!

4.2 RHEL-7

[root@rhel-7 ~]# vim /usr/bin/vmset.sh
#!/bin/bash
ifconfig $1 &> /dev/null || {echo "net device $1 is not exist"exit
}ping -c1 -w1 $2 &> /dev/null && {echo "$2 is exist"exit
}grep $1 -r /etc/sysconfig/network-scripts/ | awk -F : '{system("rm -rf " $1)}'cat >/etc/sysconfig/network-scripts/ifcfg-$1 <<EOF
DEVICE=$1
NAME=$1
BOOTPROTO=none
IPADDR0=$2
PREFIX0=24
GATEWAY0=172.25.254.2
DNS1=114.114.114.114
ONBOOT=yes
EOFnmcli connection reload
nmcli connection up $1hostnamectl set-hostname $3grep -e "$2\t$3" /etc/hosts || {echo -e "$2\t$3"  >> /etc/hosts
}[root@rhel-7 ~]# chmod +x /usr/bin/vmset.sh# 编写之前可以将原有的网卡配置文件删除!

5.网卡名称调整及禁用SELinux

5.1 RHEL-9

[root@RHEL-9 ~]# grubby --update-kernel  ALL --args net.ifnames=0   # reboot之后生效
# 永久修改Linux系统的内核启动参数,具体作用是禁用可预测的网络接口命名规则,强制系统使用传统的eth0, eth1等命名方式# 在内核启动参数中注入selinux=0,阻止内核加载SELinux安全模块
[root@RHEL-9 ~]# grubby --update-kernel  ALL --args selinux=0
# 或者使用下面的命令
# 系统启动时仍加载SELinux模块,但立即将其设为禁用状态
[root@RHEL-9 ~]# sed -i '/^SELINUX=/ c SELINUX=disabled' /etc/selinux/config

image-20250829091953321

5.2 RHEL-7

[root@rhel-7 ~]# grubby --update-kernel  ALL --args net.ifnames=0   # reboot之后生效[root@rhel-7 ~]# grubby --update-kernel  ALL --args selinux=0
# 或者使用下面的命令
# 系统启动时仍加载SELinux模块,但立即将其设为禁用状态
[root@rhel-7 ~]# sed -i '/^SELINUX=/ c SELINUX=disabled' /etc/selinux/config

6.火墙的关闭

]# systemctl disable --now firewalld
]# reboot

7.reboot 测试 + Poweroff 永久关闭-母盘制作完毕

vmset.sh 网卡名 IP地址 主机名# 以后需要虚拟机,直接从母盘克隆出子盘即可!
# 示例如下:

8.克隆母盘-子盘的使用方法

image-20251031140819855

image-20251031140923418

这里建议使用"创建链接克隆"

# 以后克隆出来开机之后直接执行即可 vmset.sh 网卡名 IP地址 主机名
[root@localhost ~]# vmset.sh eth0 172.25.254.10 R9-node1.cyber4k.org[root@R9-node1 ~]# hostname
R9-node1.cyber4k.org[root@R9-node1 ~]# more /etc/NetworkManager/system-connections/eth0.nmconnection 
[connection]
id=eth0
type=ethernet
interface-name=eth0[ipv4]
address1=172.25.254.10/24,172.25.254.2
dns=114.114.114.114;
method=manual[root@R9-node1 ~]# cat /etc/resolv.conf 
nameserver 114.114.114.114[root@R9-node1 ~]# route -n
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.25.254.2    0.0.0.0         UG    100    0        0 eth0
172.25.254.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
[root@localhost ~]# vmset.sh eth0 172.25.254.100 R7-node1.cyber4k.org[root@localhost ~]# hostname
r7-node1.cyber4k.org[root@localhost ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
NAME=eth0
BOOTPROTO=none
IPADDR0=172.25.254.100
PREFIX0=24
GATEWAY0=172.25.254.2
DNS1=114.114.114.114
ONBOOT=yes[root@localhost ~]# cat /etc/resolv.conf
search cyber4k.org
nameserver 114.114.114.114
[root@localhost ~]# route -n
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.25.254.2    0.0.0.0         UG    100    0        0 eth0
172.25.254.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
http://www.dtcms.com/a/558925.html

相关文章:

  • 东莞网站建设优化技术成都网站建设哪家
  • 永久免费的wap建站平台宿松网站建设设计
  • 大连网站怎么推广360seo关键词优化
  • 自己做qq头像的网站中卫企业管理培训网站
  • 大良网站建设如何wordpress的登录地址
  • 番禺建设局网站首页如何给网站做右侧导航栏
  • 如何做响应式的网站外贸做那种网站
  • 响应式环保网站模板下载wordpress头像上传插件
  • 个人网站企业网站网站自助建站软件
  • 环保网站 中企动力建设深圳哪些公司需要做网站
  • 网站备案 流程介绍几个有趣的网站
  • wordpress整体加速seo上海公司
  • 江油网站建设制作策划哪家专业技术支持 东莞网站建设
  • STM32项目分享:基于STM32的小区无线手机充电装置设计
  • 上海网站建设公司招聘wordpress 菜单怎么使用方法
  • 风雨同舟 网站建设领动云建站
  • 高邮市城乡建设局网站中装建设公司怎么样
  • 自己做报名网站教程搜索引擎seo排名优化
  • 服装网站建设的技术可行性企业文化墙制作
  • SSH连接虚拟机失败排查指南
  • 连云制作企业网站wordpress获取评论用户
  • 徐州网站开发案例wordpress5.2附加域
  • 3 如何进行网站优化设计百度推广二级代理商
  • 网站跳转qqWordPress底部添加音乐
  • 免费网站平台推荐江苏企业网站制作哪家好
  • 记录一个hel_delay失效的情况
  • 做logo的网站教师网络培训心得体会
  • Windows MFC添加类,变量,类导向
  • 图片去重工具:DuplicatePhotoFinder - 图片去重.rar 操作指南
  • 商洛做网站的公司电话wordpress添加单页