设为首页 收藏本站
查看: 378|回复: 0

[经验分享] kickstart全自动安装Linux

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-3-30 08:33:47 | 显示全部楼层 |阅读模式
今天晚上在这里和大家分享一下如何利用kickstart全自动安装Linux,当然还有别的工具可以全自动的安装Linux,每个工具都有它自己的优点和缺点,选择一个适合你的就好了。

    需要的软件包:nfs*   dhcp*   tftp*


一、安装软件

    先把上面的三个软件包安装好
1
2
3
yum install nfs* -y
yum install dhcp* -y
yum install tftp* -y



二、拷贝光盘内容
    在根分区中建立一个目录

1
mkdir /redhatinstall



    挂载光盘,拷贝光盘内容到这个目录下

1
2
mount -o loop /dev/cdrom /media
cp -r /media/* /redhatinstall




三、配置nfs
    编辑 nfs 的共享配置文件

1
echo "/redhatinstall *(rw,sync)" >> /etc/exports



把我们刚刚拷贝近光盘的那个目录共享出去,*表示任何ip都可以mount这个目录。

四、配置dhcp服务器
1
2
3
4
5
6
7
[iyunv@server ~]# cat /etc/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample  
#[iyunv@server ~]# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp: overwrite `/etc/dhcpd.conf'? y
[iyunv@server ~]#



    通过命令我们可以看到,dhcp的默认配置文件中没有内容,有一个提示说,我们可以参考 /usr/share/doc/dhcp*/dhcpd.conf.sample 这个示例文件。

    所以我们把这个文件拷贝过来,直接覆盖。

下面我们打开这个文件进行配置
1
2
3
4
5
6
7
8
9
10
11
12
13
      1 ddns-update-style interim;
      2 ignore client-updates;
      3
      4 subnet 192.168.21.0 netmask 255.255.255.0 {
      5
      6         option routers                  192.168.21.1;
      7         option subnet-mask              255.255.255.0;
      8         range dynamic-bootp 192.168.21.100 192.168.21.200;
      9         default-lease-time 21600;
     10
     11         next-server 192.168.21.10;
     12         filename "pxelinux.0";
     13 }



这是我的配置文件,其中 subnet 代表要分配ip所处的网段,option routers 表示默认网关,range dynamic-bootp 表示,分配ip的范围,next-server 表示要去那个ip服务器读取文件,filename表示读取哪个文件。

五、配置TFTP
    修改文件 /etc/xinetd.d/tftp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
      1 # default: off
      2 # description: The tftp server serves files using the trivial file transfer \
      3 #       protocol.  The tftp protocol is often used to boot diskless \
      4 #       workstations, download configuration files to network-aware printers, \
      5 #       and to start the installation process for some operating systems.
      6 service tftp
      7 {
      8         socket_type             = dgram
      9         protocol                = udp
     10         wait                    = yes
     11         user                    = root
     12         server                  = /usr/sbin/in.tftpd
     13         server_args             = -s /tftpboot
     14         disable                 = yes
     15         per_source              = 11
     16         cps                     = 100 2
     17         flags                   = IPv4
     18 }



把14行的disable的值改为 no。
    然后进入  /tftpboot 目录
1
2
3
4
[iyunv@server ~]# cd /tftpboot/
[iyunv@server tftpboot]# ls
linux-install
[iyunv@server tftpboot]#



只有一个目录,这时候我们需要copy几个文件到这个 tftpboot目录下面
1
2
3
4
[iyunv@server tftpboot]# cp /redhatinstall/images/pxeboot/{initrd.img,vmlinuz} .
[iyunv@server tftpboot]# ls
initrd.img  linux-install  vmlinuz
[iyunv@server tftpboot]#



接着再拷贝一个文件,就是刚刚我们在dhcpd.conf配置文件中配置的  pxelinux.0 文件。
1
2
3
4
[iyunv@server tftpboot]# cp /usr/lib/syslinux/pxelinux.0 .
[iyunv@server tftpboot]# ls
initrd.img  linux-install  pxelinux.0  vmlinuz
[iyunv@server tftpboot]#



我们再建立一个目录,拷贝一个文件到这个目录下面:
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@server pxelinux.cfg]# pwd
/tftpboot/pxelinux.cfg
[iyunv@server pxelinux.cfg]# cp /redhatinstall/isolinux/isolinux.cfg default
[iyunv@server pxelinux.cfg]# ls
default
[iyunv@server pxelinux.cfg]# ll
total 4
-r-xr-xr-x 1 root root 366 Mar 29 22:39 default
[iyunv@server pxelinux.cfg]# chmod 755 default
[iyunv@server pxelinux.cfg]# ll
total 4
-rwxr-xr-x 1 root root 366 Mar 29 22:39 default
[iyunv@server pxelinux.cfg]#



记得修改权限,要不然我们没法编辑。接下来编辑这个文件 default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
      1 default linux
      2 prompt 1
      3 timeout 600
      4 display boot.msg
      5 F1 boot.msg
      6 F2 options.msg
      7 F3 general.msg
      8 F4 param.msg
      9 F5 rescue.msg
     10 label linux
     11    kernel linuz
     12    append ks=nfs:192.168.21.10:/redhatinstall/ks.cfg initrd=initrd.img
     13
     14
     15 #label linux
     16 #  kernel vmlinuz
     17 #  append initrd=initrd.img
     18 label text
     19   kernel vmlinuz
     20   append initrd=initrd.img text
     21 label ks
     22   kernel vmlinuz
     23   append ks initrd=initrd.img
     24 label local
     25   localboot 1
     26 label memtest86
     27   kernel memtest
     28   append -
     29



第10-12行是我自己添加进去的。ks=nfs:192.168.21.10:/redhatinstall/ks.cfg 表示我们读取nfs服务器上的ks.cfg 文件的路径。


六、拷贝ks.cfg文件
    Linux系统安装完后我们可以在root的家目录下看到有一个 anaconda-ks.cfg 文件,我们把这个文件拷贝到 /redhatinstall 目录下面,并改名为 ks.cfg。
1
2
3
4
5
[iyunv@server ~]# cp anaconda-ks.cfg /redhatinstall/ks.cfg
[iyunv@server ~]# cd /redhatinstall/
[iyunv@server redhatinstall]# ll ks.cfg
-rw------- 1 root root 1107 Mar 29 22:44 ks.cfg
[iyunv@server redhatinstall]#



把这个问价的权限改为 777。然后编辑这个文件,下面是我的配置信息,想要看看每个选项是什么意思的话,可以去这里看http://www.iyunv.com/Linux/2013-07/87299.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
      # Kickstart file automatically generated by anaconda.

      install
      text
      key --skip
      lang en_US.UTF-8
      keyboard us
      xconfig --startxonboot
      network --device eth0 --bootproto dhcp
      rootpw oracle
      firewall --diabled
      authconfig --enableshadow --enablemd5
      nfs --server=192.168.21.10 --dir=/redhatinstall
     selinux --diabled
     timezone --utc Asia/Shanghai
     bootloader --location=mbr --driveorder=sda --append="rhgb quiet"
     clearpart --linux
     part /boot --fstype ext3 --size=200
     part swap --size=3000
     part / --fstype ext3 --size=100 --grow
     %packages
     @admin-tools
     @base
     @core
     @dialup
     @editors
     @gnome-desktop
     @graphical-internet
     @graphics
     @legacy-software-support
     @printing
     @system-tools
     @text-internet
     @base-x
     kexec-tools
     fipscheck
     device-mapper-multipath
     sgpio
     emacs
     libsane-hpaio
     festival
     audit
     xorg-x11-utils
     xorg-x11-server-Xnest
     reboot



配置好这个文件后,我们把需要的服务都启动起来
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@server redhatinstall]#
[iyunv@server redhatinstall]# service dhcpd restart
Starting dhcpd:                                            [  OK  ]
[iyunv@server redhatinstall]# service xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]
[iyunv@server redhatinstall]# service nfs restart
Shutting down NFS mountd:                                  [FAILED]
Shutting down NFS daemon:                                  [FAILED]
Shutting down NFS quotas:                                  [FAILED]
Shutting down NFS services:                                [FAILED]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
[iyunv@server redhatinstall]#



    全部OK,记得启动dhcp服务的时候,一定保证本机的ip是static的。
这个时候,我们新建一个虚拟机,让这个虚拟机和刚才我们配置好的服务器都用桥接模式,我们不挂载光盘,直接启动。就开始自动安装了。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-51952-1-1.html 上篇帖子: [性能分析]linux文件描述符 下篇帖子: centos6安装完成后NetworkManager无法识别wifi Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表