PXE多机无人值守安装+批量用户创建并限定登录地点

来源:互联网 发布:海马电动车数据 编辑:程序博客网 时间:2024/05/18 18:46

无人值守系统安装

需求:自动检测安装,支持多台主机

所用工具:dhcp、tftp-server、httpd、syslinux
(注:所用主机IP:192.168.230.164 /24)
实现:

1、  安装和配置所需服务#挂载光盘[root@localhost ~]# mount /dev/cdrom /mnt/mount: block device /dev/sr0 is write-protected, mounting read-only#注释原有的yum源[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo[base]…name=CentOS-$releasever - Basemirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infrabaseurl=file:///var/www/html/OS  #修改光盘挂载点gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-62、  安装PXE所需服务dhcp:             分配给客户端提供的IP地址;tftp-server:         tftp服务器端, 提供系统安装所需文件;xinetd:            tftp服务超级守护进程, 用于唤醒tftp服务;httpd:            基于http服务提供安装源;syslinux:         提供pxelinux.0文件, 此文件用于引导系统, 相当于bootloader;[root@localhost ~]# yum -y install dhcp tftp-server xinetd syslinux httpd3、  配置dhcp和tftp服务[root@localhost ~]# vim /etc/dhcp/dhcpd.confallow booting;allow bootp;ddns-update-style interim;ignore client-updates;subnet 192.168.230.0 netmask 255.255.255.0 {        option subnet-mask      255.255.255.0;        option domain-name-servers  192.168.230.164;        range dynamic-bootp 192.168.230.1 192.168.230.50;        default-lease-time      21600;        max-lease-time          43200;        next-server             192.168.230.164;        filename                "pxelinux.0";}[root@localhost ~]# vim /etc/xinetd.d/tftpservice tftp{        socket_type             = dgram        protocol                = udp        wait                    = yes        user                    = root        server                  = /usr/sbin/in.tftpd        server_args             = -s /var/lib/tftpboot        disable                 = no        #改这里,由yes改为no        per_source              = 11        cps                     = 100 2        flags                   = IPv4}[root@localhost ~]# service dhcpd configtest  #语法测试[root@localhost ~]# service dhcpd start    #启动dhcp服务[root@localhost ~]#chkconfig dhcpd on               #将dhcp设置为开机自启[root@localhost ~]#service xinetd configtest         #测试语法是否正确[root@localhost ~]#service xinetd start                  #启动xinetd服务[root@localhost ~]#chkconfig xinetd on                #将xinetd设置为开机自启动**######配置防火墙!!!见最下面**    (如果service命令不管用,可以到/etc/init.d/下直接启动)4、  配置http服务[root@localhost ~]mkdir /var/www/html/OS[root@localhost ~]cp -rf /mnt/* /var/www/html/OS[root@localhost ~]service  httpd start[root@localhost ~]chkconfig httpd on5、  复制kickstart所需文件[root@localhost ~]mkdir /var/lib/tftpboot/pxelinux.cfg[root@localhost ~]cd /var/lib/tftpboot[root@localhost tftpboot]#cp /usr/share/syslinux/pxelinux.0 . [root@localhost tftpboot]#cp /mnt/images/pxeboot/{vmlinux,initrd.img} .[root@localhost tftpboot]#cp /mnt/isolinux/{vesamenu.c32,boot.msg} .[root@localhost tftpboot]#cp /mnt/isolinux/isolinux.cfg   /pxelinux.cfg/default[root@localhost ~]# ls /var/lib/tftpboot/boot.msg  initrd.img  pxelinux.0  pxelinux.cfg  vesamenu.c32  vmlinuz#修改/var/lib/tftpboot/pxelinux.cfg/default文件,添加ks.cfg文件位置#修改成最简化[root@localhost tftpboot]# vim pxelinux.cfg/defaultdefault vesamenu.c32#prompt 1timeout 6display boot.msglabel ks  kernel vmlinuz  append initrd=initrd.img ks=http://192.168.230.164/ks.cfg6、  提供ks.cfg文件(可自己创建,也可用system-config-kickstart生成)记得改URL#ks.cfg样板(可用自制ISO中的ks.cfg,修改网络安装)[root@localhost ~]# vi /var/www/html/ks.cfg#platform=x86, AMD64, 或 Intel EM64T#version=DEVEL# Firewall configurationfirewall --disabled# Install OS instead of upgradeinstall# Use network installationurl --url=http://192.168.230.164/OS    #改这,由cdrom改为url#repo --name="Centos" --baseurl=http://192.168.230.164 --cost=100# Root passwordrootpw --iscrypted $1$Kldv3XiW$fBgcVMAyKrKeHjPXh8IID/# System authorization informationauth  --useshadow  --passalgo=sha512# Use graphical installgraphicalfirstboot --disable# System keyboardkeyboard us# System languagelang zh_TW# SELinux configurationselinux --disabled# Installation logging levellogging --level=info# Reboot after installationreboot# System timezonetimezone  Asia/Shanghai# Network informationnetwork  --bootproto=dhcp --device=eth0 --onboot=on# System bootloader configurationbootloader --location=mbr# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart --all --initlabel# Disk partitioning informationpart /boot --asprimary --fstype="ext4" --size=500part swap --fstype="swap" --size=2000part / --asprimary --fstype="ext4" --grow --size=1%packages@base@basic-desktop@chinese-support@debugging@desktop-debugging@desktop-platform@directory-client@fonts@ftp-server@general-desktop@graphical-admin-tools@input-methods@internet-applications@internet-browser@java-platform@legacy-x@network-file-system-client@office-suite@print-client@remote-desktop-clients@server-platform@x11%end[root@localhost ~]最后一点!!!一定要配防火墙!!![root@linuxprobe ~]# firewall-cmd --permanent --add-port=69/udpsuccess[root@linuxprobe ~]# firewall-cmd --reload success[root@linuxprobe ~]# firewall-cmd --permanent --add-service=dhcpsuccess[root@linuxprobe ~]# firewall-cmd --reload success[root@linuxprobe ~]# firewall-cmd --permanent --add-service=ftpsuccess[root@linuxprobe ~]# firewall-cmd --reload success至此,完成服务器搭建新建虚拟机测试,虚拟机不用加载镜像,选NAT模式。————————————————————————————————————————批量创建用户,并同时禁止本地登录#!/bin/bashsed -i '/account/{s/$/\naccount   required   \/lib64\/security\/pam\_access\.so/;:f;n;b f;}'  /etc/pam.d/login#添加禁止普通用户登录模块i=0#批量创建普通用户while [ "$i" != "50" ]do        i=$(($i+1))        username="YX"${i}        echo "$username"        useradd -m $username        echo $username | passwd --stdin $username        sed -i '/account/{s/$/\naccount   required   \/lib64\/security\/pam\_access\.so/;:f;n;b  f;}' /etc/pam.d/login        sed -i "i\-:\$username:locol" /etc/security/access.conf#确定禁止登录的普通用户doneecho "creat 50 users"

**克隆时需要更改的点:
1、 vim /etc/dhcp/dhcpd.conf/
2、 vim /var/lib/tftpboot/pxelinux.cfg/default
3、 vi /var/www/html/ks.cfg**

任务难点:
1、 在配置dhcp服务时,总是开启不了服务,后来是换了镜像才弄好,原因待定。。。
2、 脚本的本地登录。由于自身知识漏洞,没有理解Linux本地登录原理,一个劲的在桌面登录面前瞎折腾,后来黄哥指点,通过黑屏登录才是locallogin.鸟哥继续学习ing。
3、 Sed命令不会用,卡了一天,通过网上询问,和问陈烽搞定。Shell继续学习ing。
4、 引导文件在最后运行脚本文件时一直卡死不动,但系统并没有死,不清楚原因,改变策略,将脚本文件写成开机自启动,并加入运行完后自我删除命令。

#!/bin/bashexpect -c "   spawn su - root   expect \"Password:\"   send \"123456\r\"   interact  "  sed -i '/account/{s/$/\naccount   required   \/lib64\/security\/pam\_access\.so/;:f;n;b f;}' /etc/pam.d/logini=0while [ "$i" != "50" ]do        i=$(($i+1))        username="YX"${i}        echo "$username"        useradd -m $username        echo $username | passwd --stdin $username        sed -i '/account/{s/$/\naccount   required   \/lib64\/security\/pam\_access\.so/;:f;n;b f;}' /etc/pam.d/login        sed -i "i\-:\$username:locol" /etc/security/access.confdoneecho "creat 50 users"/bin/rm $0
0 0
原创粉丝点击