Ubuntu系统批量自动安装

按照上面两个思路,那就研究下批量安装Ubuntu系统的方法!

历史上,很多同学都遇到过和我同样的问题,机器太多,需要挨个装机,简直就是折磨!

于是,为了降低批量装机的难度,出现了PXE技术,它将操作系统远程下载到本地运行,有了这个技术,我们就不需要再挨个机器插U盘安装系统。

有了PXE技术,依然需要在安装的过程中不停地与机器进行交互,设置选项,费时费力。为了减轻同学们的工作量,RedHat推出了kickstart,在安装操作系统前将其中出现的各种问题的应答内容提前写好,使整个操作系统的安装可以自动完成。Debian系的Ubuntu等感觉kickstart对自己不够友善,不能完全满足自己的要求,于是推出了preseed。

再后来,因为kickstart难度系数太高,RedHad又推出了cobbler,把批量装机的难度降低到了小学水平。

PXE是Intel公司开发的将操作系统远程下载到本地运行的一种技术。

本地网卡ROM中包含有PXE客户端软件。网卡启动时会发出DHCP请求,从PXE服务器端获得动态IP地址、网关及TFTP服务器信息后,它会自动下载一个用于引导操作系统的启动软件包到本地内存(不同的操作系统使用不同的PXE引导文件)中,再通过此软件加载操作系统启动文件,从而开始操作系统的安装工作。

在我们手动安装操作系统时,需要回答各种提示问题,而针对某种特定应用时,这种回答完全有章可循,如果我们能在安装操作系统时将其中出现的各种问题的应答内容提前写好,那么整个操作系统的安装就可以自动完成。

kickstart是RedHat公司针对自动安装RedHat、Fedora与CentOS这3种同一体系的操作系统而制定的问答规范。它一般会以.cfg作为文件后缀名,不仅可以自动应答一些简单问题,还可以指定操作系统需要安装的各种软件包,更可以在操作系统完装完成后自动执行一些脚本,这些脚本可以让我们直接配置系统。

通常,kickstart配置文件通过命令行工具system-config-kickstart生成。当然,我们更喜欢在CentOS图形界面环境下生成用于定制操作系统安装的配置文件。

preseed则是Debian/Ubuntu操作系统自动安装的问答规范,同样可以预定义Ubuntu如何安装,其配置更多通过手动处理。

RedHat在2008年发布了网络安装服务器套件cobbler(补鞋匠),它集成了PXE、DHCP、HTTP、TFTP、kickstart等服务,相对之前的kickstart,能够更加快捷、方便的批量布署redhat、centos类系统。

由上面的基础概念我们了解到,可选择的技术组合有:

PXE服务器选择我们手动安装好的那一台,系统是Ubuntu14.04.5Server(64-bit)版,当前IP为172.16.0.213。

配置为PXE服务器后网段为10.0.0.0/8,IP为10.0.0.100。

1、安装isc-dhcp-serversudoapt-getupdate

sudoapt-getinstallisc-dhcp-server-y

2、查看网卡和ipipadd或者ifconfig,查看正在使用的局域网网卡,假设为eth0。

3、指定dhcp网卡sudovim/etc/default/isc-dhcp-server拉到最底部,修改为:

INTERFACES="eth0"4、配置dhcp服务sudovim/etc/dhcp/dhcpd.conf在文件末尾添加:

subnet10.0.0.0netmask255.0.0.0{range10.0.0.10110.0.0.200;optionsubnet-mask255.0.0.0;optionrouters10.0.0.100;optionbroadcast-address10.255.255.255;filename"pxelinux.0";next-server10.0.0.100;}子网和掩码可以根据自己的需要设置。

filename"pxelinux.0";,指定PXE启动文件名。next-server10.0.0.100;,指定PXE服务器IP地址,TFTP服务器IP地址。

5、重启服务serviceisc-dhcp-serverrestart

备注:也可以安装DNSmasq,DNSmasq实际上是一个集成工具,包含了DNS、DHCP、TFTP服务器。

1、安装tftpd-hpaapt-getinstalltftpd-hpa-y

2、给根目录添加读写权限sudochmod777/var/lib/tftpboot/

3、测试tftpsudoapt-getinstalltftp-y

cd~

tftp127.0.0.1

getversion.info

4、tftpd开启关闭命令sudo/etc/init.d/tftpd-hpastart

sudo/etc/init.d/tftpd-hpastop

1、安装apache2sudoapt-getinstallapache2-y

web根目录是/var/www/html/

2、测试apache2curl127.0.0.1

3、重启命令sudo/etc/init.d/apache2restart

1、上传ubuntu-14.04.5-server-amd64.iso到用户目录。使用xftp上传,或者使用scp命令,这里使用scp命令。打开gitbash,执行:scpubuntu-14.04.5-server-amd64.isotest@172.16.0.213:~

2、挂载ubuntu-14.04.5-server-amd64.iso到ubuntu目录。在用户目录执行:sudomkdir/var/www/html/ubuntu

sudomountubuntu-14.04.5-server-amd64.iso/var/www/html/ubuntu

3、拷贝部分文件到tftpsudocp-r/var/www/html/ubuntu/install/netboot/*/var/lib/tftpboot/

4、拷贝seed文件到web根目录sudocp/var/www/html/ubuntu/preseed/ubuntu-server.seed/var/www/html/

5、编辑seed文件sudovim/var/www/html/ubuntu-server.seed

在文件末尾添加:

ks.cfg中保存的是安装系统过程中默认的系统配置,没有这个文件就需要安装中手动设置。kickstart则是方便编辑这个文件的,不用它的话也可以手工编辑

kickstart需要GUI界面,我因为是安装的server,所以需要安装桌面(如果是desktop版本就不需要)。

1、安装图形界面sudoapt-getinstallubuntu-desktop-y

过程非常久,请先去继续读论文。

2、安装kickstartsudoapt-getinstallsystem-config-kickstart-y

3、使用屏幕键盘连接主机,进入图形界面sudostartx,或者直接重启sudoreboot

4、点击右上角“Searchyourcomputerandonlineresources”,搜索kickstart,启动kickstart。

5、然后,按照图示选择kickstart的配置。

6、保存ks.cfg后,查看ks.cfg内容为:

8、修改txt.cfgsudovim/var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg,原txt.cfg为:

defaultinstalllabelinstallmenulabel^Installmenudefaultkernelubuntu-installer/amd64/linuxappendvga=788initrd=ubuntu-installer/amd64/initrd.gz---quietlabelclimenulabel^Command-lineinstallkernelubuntu-installer/amd64/linuxappendtasks=standardpkgsel/language-pack-patterns=pkgsel/install-language-support=falsevga=788initrd=ubuntu-installer/amd64/initrd.gz---quiet修改为:

#D-Iconfigversion2.0includeubuntu-installer/amd64/boot-screens/menu.cfgdefaultubuntu-installer/amd64/boot-screens/vesamenu.c32prompt0timeout60timeout默认是0,改为60(6秒后自动选择install选项)。

1、重新配置IPsudovim/etc/network/interfaces,修改eth0的IP为10.0.0.100:

#Thisfiledescribesthenetworkinterfacesavailableonyoursystem#andhowtoactivatethem.Formoreinformation,seeinterfaces(5).#Theloopbacknetworkinterfaceautoloifaceloinetloopback#Theprimarynetworkinterfaceautoeth0ifaceeth0inetstaticaddress10.0.0.100gateway10.0.0.100netmask255.0.0.02、重启eth0sudoifdowneth0,sudoifupeth0

3、重启dhcpsudoserviceisc-dhcp-serverrestart

4、重新挂载镜像sudomountubuntu-14.04.5-server-amd64.iso/var/www/html/ubuntu

5、检查各个服务psaux|grepdhcp

psaux|grepapache

psaux|greptftp

6、把PC和PXE服务器连接到同一个交换机,测试一下PC能否获取到IP。

1、把PXE服务器和需要安装系统的主机(下文统一称为目标主机)连接到同一个交换机。

2、目标主机开机启动进入BIOS,首选启动项选择PXE,保存退出。

3、然后,目标主机就会自动获取IP地址,连接PXE服务器,进入到安装界面。[图片上传失败...(image-151f9d-1545010021441)]

4、在自动网络配置的时候失败,报错“Networkautoconfigurationfailed”,多次尝试依然失败。

Alt+F1,切换回安装界面,这时需要手动配置,一次不行就再来一次。

5、安装过程中,分区后卡住,需要手动选择确认分区。

6、之后,无需任何操作,直到安装成功。

以上安装过程,已经省去了很多交互步骤,但是依然比较麻烦,主要存在两个问题:一个是自动配置网络的问题,一个是需要分区确认的问题。下面尝试解决这两个问题。

#Thisfiledescribesthenetworkinterfacesavailableonyoursystem#andhowtoactivatethem.Formoreinformation,seeinterfaces(5).#Theloopbacknetworkinterfaceautoloifaceloinetloopback#Theprimarynetworkinterfaceautoeth0ifaceeth0inetstaticaddress10.0.0.100netmask255.0.0.0gateway10.0.0.100broadcast10.255.255.255dns-nameservers10.0.0.100重启网络,sudoifdowneth0,sudoifupeth0。重启dhcp,sudoserviceisc-dhcp-serverrestart。问题依旧。

allowbooting;allowbootp;optionoption-128code128=string;optionoption-129code129=text;next-server10.0.0.100;filename"pxelinux.0";重启dhcp,sudoserviceisc-dhcp-serverrestart。问题依旧。

d-inetcfg/choose_interfaceselectautod-inetcfg/get_hostnamestring$hostname问题依旧。

d-inetcfg/choose_interfaceselecteth0d-inetcfg/dhcp_timeoutstring60d-inetcfg/get_hostnamestringubuntud-inetcfg/get_domainstringubuntu-domain问题依旧。

d-inetcfg/choose_interfaceselecteth0d-inetcfg/dhcp_failednoted-inetcfg/dhcp_optionsselectDonotconfigurethenetworkatthistimed-inetcfg/get_hostnamestringubuntud-inetcfg/get_domainstringubuntu-domain问题依旧。

#Ifyouprefertoconfigurethenetworkmanually,uncommentthislineand#thestaticnetworkconfigurationbelow.d-inetcfg/disable_dhcpbooleantrued-inetcfg/disable_autoconfigbooleantrued-inetcfg/use_autoconfigbooleanfalse#Ifyouwantthepreconfigurationfiletoworkonsystemsbothwithand#withoutadhcpserver,uncommenttheselinesandthestaticnetwork#configurationbelow.d-inetcfg/dhcp_failednoted-inetcfg/dhcp_optionsselectConfigurenetworkmanually#Staticnetworkconfiguration.##IPv4exampled-inetcfg/get_ipaddressstring10.0.0.134d-inetcfg/get_netmaskstring255.0.0.0d-inetcfg/get_gatewaystring10.0.0.100d-inetcfg/get_nameserversstring10.0.0.100d-inetcfg/confirm_staticbooleantrue问题依旧。感觉netcfg这个系列的命令根本没有生效!

#!/bin/sh#Killallfordhcpclients.kill-all-dhcp;netcfg;forclientindhclientudhcpcpumpdhcp6c;dopid=$(pidof$client)||true["$pid"]||continueifkill-0$pid2>/dev/null;thenkill-TERM$pidsleep1#StillaliveDie!ifkill-0$pid2>/dev/null;thenkill-KILL$pidfifidone(2)变更权限sudochmoda+x/var/www/html/run.sh

(3)在ubuntu-server.seed文件中添加一行:

d-ipreseed/runstringrun.sh问题依旧,但是Alt+F2进入命令行,发现获取的IP确实没有了。

9、莫非,是因为DHCP的网段问题?折腾了一个多小时,PXE服务器地址换成192.168.34.1,DHCP换成了192.168.34.0网段,然而并没有什么用。

sudovim/var/www/html/ks.cfg,添加:

preseedpartman-lvm/confirm_nooverwritebooleantrue问题依旧。

2、sudovim/var/www/html/ks.cfg,添加:

preseedpartman-lvm/confirm_nooverwritebooleantruepreseedpartman-lvm/device_remove_lvmbooleantruepreseedpartman/confirm_write_new_labelbooleantruepreseedpartman/confirmbooleantruepreseedpartman/confirm_nooverwritebooleantrue问题依旧。

d-ipartman/confirm_write_new_labelbooleantrued-ipartman/choose_partitionselectFinishpartitioningandwritechangestodiskd-ipartman/confirmbooleantrue分区成功,吼吼吼!折腾了一整天,总算有点成就,泪流满面。。。让我安静的哭一会。。。

配置Ubuntu批量自动安装的过程中,发现最重要的两个文件是/var/www/html/ks.cfg和/var/www/html/ubuntu-server.seed,因为他们两个是控制交互的。

折腾的过程中学到了很多东西,而最终的成果,除了网络需要手动配置之外,其他都很满意。我会继续尝试解决网络配置的问题,有了进展,再更新本文。

THE END
1.192.168.0.10110.0.0.0 - 10.255.255.255 最常用的地址范围是192.*-,有时候会用到10.*-范围里的地址。 少数情况下用到172.*-范围。如果你想了解更多关于 IP 地址的信息,请查看我们的文章什么是 IP 地址,为什么它很重要? 192.168.0.101 在D-Link, Netgear & SerComm路由器中常见 https://www.router-reset.com/zh-hans/ip/192-168-0-101
2.电信校园网wifi认证登录入口正君科技10.255.0.101.校园网登录-dlou校园网认证登录入口 校园网登录入口随着数字化时代的到来,校园网络已经成为学生们学习和生活的重要基础设施。然而,学校的网络2024-12-20 02:58:13 - 哈尔滨seo GiWiFi校园网登录入口-giwifi校园网连接不上 近年来,随着移动互联网的普及,越来越多的高校学生选择了使用校园WiFi进行https://www.zhenseo.com/show/2750154.html
3.Linux性能调优之硬件资源监控rasmcctlconfiguration: autonegotiation=on broadcast=yes driver=igb driverversion=5.19.0-32-generic duplex=full firmware=1.61, 0x80000cd5, 1.949.0 ip=10.255.0.101 latency=0 link=yes multicast=yes port=twisted pair speed=100Mbit/s resources: irq:16 memory:efd00000-efdfffff ioport:5000(size=32) memory:https://blog.csdn.net/qq_48811377/article/details/138973268
4.IP位址資訊(10.102.0.010.102.0.101 10.102.0.102 10.102.0.103 10.102.0.104 10.102.0.105 10.102.0.106 10.102.0.107 10.102.0.108 10.102.0.109 10.102.0.110 10.102.0.111 10.102.0.112 10.102.0.113 10.102.0.114 10.102.0.115 10.102.0.116 10.102.0.117 10.102.0.118 10.102.0.119 10.102.0.120 10.102.0.121 10.102.0.122 10.102.0.123 https://tw.ntunhs.net/IPInfo/B5/10/102.htm
5.BasicComputerNetworkingforTheaterQLab4Documentation10.0.0.0through10.255.255.255for a total of 16,777,216 addresses. When you set up a private network, you’re generally going to want to use one of these three address schemes. If your private network never, ever connects to the internet, there’s nothing stopping you from using any addreshttps://qlab.app/docs/v4/tutorials/networking/
6.WelcometoPDBbind58.929 3.154 1.00 42.16 n atom 1037 ca glu a 89 98.424 58.870 1.701 1.00 47.75 c atom 1038 c glu a 89 97.122 59.402 1.103 1.00 51.14 c atom 1039 o glu a 89 97.145 60.118 0.101 1.00 52.09 o atom 1040 cb glu a 89 98.688 57.429 1.245 1.00 48.52 c atom 1041 cg glu a 89 98.751 http://www.pdbbind.org.cn/quickpdb.php?quickpdb=2Q8M
7.PropertiesofQQˉ(Q?b,c)mesonsinCoulombplus10.255 10.255 10.260 23P0 10.061 10.148 10.236 10.322 10.407 10.575 10.232 10.234 10.240 21P1 10.070 10.160 10.249 10.338 10.425 10.599 10.261 10.270 33S1 10.083 10.191 10.301 10.412 10.523 10.748 10.355 10.238 10.290 31S0 10.065 10.169 10.275 10.381 10.488 10.703 10.355 10.370 43S1 10.244 10.394 http://arxiv.org/pdf/0808.2888
8.ListofallocatedIPaddressesin195.95.0.0195.95.0.101, 195.95.39.220, 195.95.24.38, 195.95.39.208, 195.95.3.236, 195.95.20.116 195.95.18.159, 195.95.31.118, 195.95.37.184, 195.95.7.248, 195.95.50.29, 195.95.62.81 195.95.32.155, 195.95.46.2, 195.95.47.119, 195.95.3.121, 195.95.20.234, 195.95.24.25 195.95.30.116, 195.95.58.31, 195.95.17.https://ip-address-lookup-v4.com/195/95/
9.转债ETF(511380)历史行情股票行情中心行情图表 实时行情推荐 成交明细 分价表 历史行情 基金资料 净值分析 十大重仓股 基本资料 主要财务指标 转债ETF(511380) 2024-12-13 15:00 实时行情 成交明细 分价表 历史行情 龙虎榜数据 从至按日按周按月 日期开盘收盘涨跌额涨跌幅最低最高成交量(手)成交金额(万)换手率 https://q.stock.sohu.com/cn/511380/lshq.shtml