#!/usr/bin/bash color(){ unset c declare -A c=([Error]=31 [Success]=32 [Warning]=33 [Info]=34) #echo -e "\033[${c[$1]}m[`date +%T`]($1) $2\033[0m" printf "\033[${c[$1]}m%-10s%-10s %-30s\033[0m\n" "[`date +%T`]" "($1)" "$2" sleep 0.5 } # pxe服务器初始化 color Info "pxe服务器初始化" curl -s -L https://download.beyourself.org.cn/shell-project/os/get-os-init.sh | sh # 安装dhcp、tftp、tftp-server、syslinux、wget、vsftpd、pykickstart color Info "安装pxe服务依赖" yum install -y dhcp tftp tftp-server syslinux wget vsftpd pykickstart # 配置dhcp color Info "配置dhcp" ipaddr=$(ip -4 -f inet a show dev ens33 | awk '/inet/{print $2}') gateway=$(ip r show dev ens33 | awk '/default via/{print $3}') cat > /etc/dhcp/dhcpd.conf << EOF ddns-update-style interim; ignore client-updates; authoritative; allow booting; allow bootp; allow unknown-clients; # A slightly different configuration for an internal subnet. subnet ${ipaddr%.*}.0 netmask 255.255.255.0 { range ${ipaddr%.*}.100 ${ipaddr%.*}.200; option domain-name-servers ${gateway}; option domain-name "server1.example.com"; option routers ${gateway}; option broadcast-address ${ipaddr%.*}.255; default-lease-time 600; max-lease-time 7200; # PXE SERVER IP next-server ${ipaddr%/*}; # DHCP server ip filename "pxelinux.0"; } EOF # 配置tftp color Info "配置tftp" cat > /etc/xinetd.d/tftp << EOF service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4 } EOF # 配置vsftpd color Info "配置vsftpd" cp /usr/share/syslinux/{pxelinux.0,menu.c32,memdisk,mboot.c32,chain.c32} /var/lib/tftpboot/ mkdir /var/lib/tftpboot/pxelinux.cfg mkdir /var/lib/tftpboot/netboot mount /dev/cdrom /mnt cp -rvf /mnt/* /var/ftp/pub cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/netboot/ cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/netboot/ cat > /var/ftp/pub/ks.cfg <> /etc/rc.local chmod a+x /etc/rc.local #yum install -y python3 python3-devel gcc #curl -s -L https://download.beyourself.org.cn/python-project/os/jumpserver-register.py -o /opt/jumpserver-register.py #pip3 install requests httpsig -i https://mirrors.aliyun.com/pypi/simple #python3 /opt/jumpserver-register.py \`ip -4 -f inet a show dev ens33 | awk '/inet/{print $2}' | cut -d'/' -f 1\` 192.168.96.180 47849e56-81b5-4fe6-a7d4-7d7578abfc32 ab17fa93-8f4f-4547-802f-be81a6197937 d6638212-8896-4596-9b30-ec0e5aa5905c 9ead5ec2-ba29-4b0a-b4d1-75657eec4306 %end EOF # 配置启动项 color Info "配置启动项" cat >/var/lib/tftpboot/pxelinux.cfg/default <