kickstart +dhcp +tftpd+apache2 自动安装ubuntu环境搭建

准备工作
1.安装KICKSTART
star@Ubuntu:~$ sudo apt-get install system-config-kickstart -y

1.1在 “应用程序\系统工具”中打开kickstart

基本的配置:

image

安装模式:这里选择http

image

引导启动选项:默认即可

image

分区情况:您可以根据实际情况进行分区

image

网络配置:增加一网卡设置为dhcp获取ip

image

认证模式可以按默认即可

用户设置:

image

防火墙和显示器的配置都可以根据需要设置,或按默认即可

软件包的选择:这里应该是ubuntu中kickstart的bug吧,没有显示可选的软件包,一会生成ks.cfg文件我们根据需要添加

image

安装前后预处理脚本,可以根据需要定制,这里简单举个例子:系统安装完之后把主机名改为 pxeclient

image

保存ks.cfg文件:

image

修改ks.cfg文件

在skipx后加入

%packages  #这是server version的没有桌面

#@ubuntu-desktop  #这是ubuntu桌面版的,如果要安装的话把#去掉

注意:alternate 既有桌面版也支持server版,所以叫做二选一

最后把ks.cfg文件移到/var/www/html目录下

#mv ks.cfg /var/www/html/

#我的配置文件内容

#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T

#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone Asia/Shanghai
#Root password
rootpw --iscrypted $1$gieKLFiM$jv5agaxq4QpX3lxpHR3UE1
#Initial user
user linux --fullname "linux" --iscrypted --password $1$y6kFWox0$S1OjQi4EbddMLnTbKoNiP0
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use Web installation
url --url http://192.168.1.156/ubuntu12
#System bootloader configuration
bootloader --location=mbr 
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel 
#Disk partitioning information
#Disk partitioning information
part /boot --fstype ext4 --size 256
part swap --size 1024
part / --fstype ext4 --size 1 --grow
#part / --fstype ext4 --size 1 --grow 
#System authorization infomation
auth  --useshadow  --enablemd5
#Network information
#network --bootproto=dhcp --device=eth0 
network --bootproto=dhcp --device=eth0 \
                        --gateway=192.168.1.1 --nameserver=8.8.8.8
#Firewall configuration
firewall --disabled 
#X Window System configuration information
xconfig --depth=8 --resolution=800x600 --defaultdesktop=GNOME --startxonboot
@ubuntu-desktop



设置好以后,保存配置文件为ks.cfg



2 安装DHCP
sudo apt-get install dhcp3-server 

2.1配置DHCP,配置文件如下
vi  /etc/dhcp/dhcpd.conf
 

subnet 192.168.1.156 netmask 255.255.255.0 {
range 192.168.1.30 192.168.1.254;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.1.156;
filename "pxelinux.0";
}


3.安装TFTP服务器
 
注意:必须使用TFTP-HPA这个软件包,使用TFTPD会出现问题导致不能导引导系统
 
star@Ubuntu:/$ sudo apt-get install tftpd-hpa tftp-hpa

配置tftp

# vim /etc/default/tftpd-hpa

增加以下两行:

RUN_DAEMON="yes" 
OPTIONS="-l -s /var/lib/tftpboot"



netboot 下载网址:http://cdimage.ubuntu.com/netboot/14.04/

下载那个netboot.tar.gz 即可

cd /var/lib/tftpboot

wget -r    http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/installer-amd64/current/images/netboot/ netboot.tar.gz 

或者  从server版本中拷贝 install下的netboot文件到tftpboot下


vim /var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg

default install 
label install 
        menu label ^Install 
        menu default 
        kernel ubuntu-installer/amd64/linux 
        append ks=  http://192.168.1.156/ks.cfg
        vga=788 initrd=ubuntu-installer/amd64/initrd.gz -- quiet  
label cli 
        menu label ^Command-line install 
        kernel ubuntu-installer/amd64/linux 
        append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language 
-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz -- quiet 

DHCP 拿不到IP
dhcp未启动 或者物理网络设置的不对
service isc-dhcp-server start 

tftp 超时 tftp服务未启动

sudo   service tftpd-hpa restart 

安装过程中卡住
http服务不好使了 无法访问www下的文件了
apache2 重启

/etc/init.d/apache2 restart 

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0

 vim /etc/apache2/apache2.conf
最后加入一句 ServerName localhost:80

apache2 默认服务目录 /var/www/html 目录 ks.cfg 和ubuntu镜像 要放在这个目录 /var/www/html 里
将镜像复制到 /var/www/html
这里用的是ubuntu-12.04.5-alternate-amd64
mkdir /var/www/html/ubuntu12
cp /media/linux/镜像名字/*   /var/www/ubuntu12/ -rf


添加网络启动的菜单选项:

/var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg

添加菜单选项
label net 
        menu label ^Net ks 
        menu default 
        kernel ubuntu-installer/amd64/linux 
        append ks=  http://192.168.1.156/ks.cfg vga=788 initrd=ubuntu-installer/amd64/initrd.gz -- quiet  

#在vm中新建一个虚拟机,这里需要注意虚拟机的网络设置,一定要和服务器在同一个网络中,否则下载不了ks.cfg文件和系统
卡在安装界面不自动安装 是因为默认等待时间 0  防止局域网内其他机器自动被重装系统

image

解决方法:

#vim /var/lib/tftpboot/pxelinux.cfg/default

timeout 1 #即设置1秒后自动选择install选项

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个搭建无人值守系统安装服务器的示例代码: 1. 配置 DHCP 服务 在 DHCP 服务器上,创建一个新的 DHCP 配置文件 `/etc/dhcp/dhcpd.conf`,并添加以下内容: ``` subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option domain-name-servers 8.8.8.8; option routers 192.168.1.1; option broadcast-address 192.168.1.255; default-lease-time 600; max-lease-time 7200; next-server 192.168.1.2; filename "pxelinux.0"; } ``` 这个配置文件指定了 DHCP 服务器的 IP 地址池(192.168.1.100 到 192.168.1.200),DNS 服务器地址(8.8.8.8),网关地址(192.168.1.1),并将默认租约时间设置为 10 分钟。 注意,这个配置文件中的 `next-server` 和 `filename` 属性指定了 PXE 服务器的 IP 地址和启动文件名。在这个示例中,我们将 PXE 服务器的 IP 地址设置为 `192.168.1.2`,将启动文件名设置为 `pxelinux.0`。 2. 配置 TFTP 服务 在 PXE 服务器上,安装 TFTP 服务器软件,并将启动文件 `pxelinux.0` 复制到 TFTP 服务器的根目录下。 3. 配置 Kickstart 文件 创建一个 Kickstart 文件 `ks.cfg`,并将其放置在 PXE 服务器的根目录下。以下是一个示例 Kickstart 文件的内容: ``` # Install OS instead of upgrade install # Use graphical installer graphical # Set up network network --bootproto=dhcp --device=eth0 # Set up root password rootpw --iscrypted $6$SALT$HASH # Configure timezone timezone Asia/Shanghai --utc # Configure partitioning autopart --type=lvm # Configure packages to install %packages @^minimal @core kexec-tools %end ``` 这个 Kickstart 文件将使用图形界面安装 CentOS 操作系统,并自动配置网络、设置 root 密码、设置时区、使用 LVM 分区,以及安装一些基本的软件包。 注意,这个 Kickstart 文件中的 `--bootproto` 参数指定了使用 DHCP 自动配置网络。这个参数的值应该与 DHCP 配置文件中的 `bootproto` 属性保持一致。 4. 配置 PXE 引导文件 创建一个 PXE 引导文件 `pxelinux.cfg/default`,并添加以下内容: ``` default ks prompt 0 timeout 300 label ks kernel vmlinuz append initrd=initrd.img ks=http://192.168.1.2/ks.cfg ``` 这个 PXE 引导文件将使用 `vmlinuz` 和 `initrd.img` 内核文件,以及之前创建的 Kickstart 文件 `ks.cfg` 来启动自动安装程序。 注意,这个 PXE 引导文件中的 `ks` 标签指定了使用 Kickstart 文件自动安装系统,`kernel` 和 `initrd` 属性指定了内核文件,`append` 属性指定了 Kickstart 文件的 URL。 5. 启动 PXE 客户端 现在,启动一个 PXE 客户端并让其从网络引导。在启动过程中,客户端将自动DHCP 服务器获取 IP 地址,并下载启动文件 `pxelinux.0`。一旦下载完成,客户端将执行这个启动文件,并自动安装操作系统。 注意,整个过程是无人值守的,只需要启动客户端并等待自动安装完成即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值