码迷,mamicode.com
首页 > 其他好文 > 详细

分享一个底层自动部署系统

时间:2020-06-04 18:09:54      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:boot   machine   接收参数   fun   varchar   配置文件   删除   out   nis   

1: 上报安装进度
curl http://100.71.70.47:8083/api/osinstall/v1/report/deviceInstallLog -X POST -d ‘{"Sn":"xxxxx","Title":"dwasd","InstallProgre":0.4}‘
2: 生成MAC 文件
curl http://100.71.70.47:8083/api/osinstall/v1/device/createIpxeConfig -X POST -d ‘{"Sn":"xxxxx","OsVersion":"bms_centos7.5-x86_64_Base"}‘
3: 增加机器
curl http://100.71.70.47:8083/api/osinstall/v1/machine/newadd -X POST -d ‘{"Sn":"xxxxx","Mac":"68:05:CA:A2:5F:B8,68:05:CA:A2:5F:B9"}‘
4: 查询机器
curl http://100.71.70.47:8083/api/osinstall/v1/machine/newlist -X POST -d ‘{"Sn":"xxxxx"}‘
5: 删除配置文件
curl http://100.71.70.47:8083/api/osinstall/v1/device/deletePxeFileByNewMac -X POST -d ‘{"Mac":"68:05:CA:A2:5F:B8,68:05:CA:A2:5F:B9"}‘
6: 接收参数
curl http://100.71.70.47:8083/api/osinstall/v1/device/ParameterInit -X POST -d ‘{"Sn":"xxxxx","Hostname":"test","Gateway":"172.168.1.1","Netmasknum":"25","Mode":"4","Vlan_id":"21","Netmode":"4","Macaddress":"01:ed:12:22:12:21:wd"}‘

6: 生成OS配置文件

DROP TABLE IF EXISTS new_macs;
CREATE TABLE new_macs ( id int(11) unsigned NOT NULL AUTO_INCREMENT,created_at timestamp NULL DEFAULT NULL,deleted_at timestamp NULL DEFAULT NULL,updated_at timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, sn varchar(255) NOT NULL, mac varchar(512) NOT NULL, status varchar(255) NOT NULL, install_progress float NULL,title varchar(255) NOT NULL,fdisk_status varchar(255) NOT NULL,PRIMARY KEY (id),UNIQUE KEY sn (sn)) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS parms;
CREATE TABLE parms ( id int(11) unsigned NOT NULL AUTO_INCREMENT,created_at timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,deleted_at timestamp NULL DEFAULT NULL,sn varchar(255) NOT NULL,parameter varchar(500) NOT NULL , PRIMARY KEY (id)) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;

insert INTO new_macs (created_at,updated_at,sn,mac,status,installProgress) values(NOW(),NOW(),"xxxxx","68:05:CA:A2:5F:B8,68:05:CA:A2:5F:B9,68:05:CA:A2:6D:E8,68:05:CA:A2:6D:E9","stat",0);

insert INTO os_configs (id,created_at,updated_at,deleted_at,name,pxe) values("17",NOW(),NOW(),NULL,"bms_centos7.5-x86_64_Base","#!ipxe
kernel http://172.16.98.253/centos7.5/images/pxeboot/vmlinuz initrd=initrd.img ksdevice=bootif ks=http://30.138.250.65/centos7.5/ks.cfg console=tty0 selinux=0 net.ifnames=0 biosdevname=0
initrd http://172.16.98.253/centos7.5/images/pxeboot/initrd.img
boot
");

make bin-x86_64-efi/ipxe.efi EMBED=uefi.ipxe
#!ipxe
dhcp
chain pxelinux.cfg/01-${netX/mac:hexhyp}
#isset ${pxelinux.cfg/01-${netX/mac:hexhyp}} && chain ${pxelinux.cfg/01-${netX/mac:hexhyp}} || chain pxelinux.cfg/default_uefi

#!ipxe
kernel http://192.168.255.133/centos/7.5/os/x86_64/images/pxeboot/vmlinuz initrd=initrd.img ksdevice=bootif ks=http://192.168.255.133/centos/ks.cfg console=tty0 selinux=0 net.ifnames=0 biosdevname=0
initrd http://192.168.255.133/centos/7.5/os/x86_64/images/pxeboot/initrd.img
boot

系统格式化:

function deleteos()
{
echo "--------------------start----dd----------------------"
fdisk -l | grep /dev | grep ‘‘ |sed ‘s/ .//g‘ | sed ‘s/[0-9]//g‘ 1>/tmp/legacy.log 2>/dev/null
fdisk -l | grep ‘Disk /dev/sd‘ | sed ‘s/Disk //g‘ | sed ‘s/:.
//g‘ 1>/tmp/uefi.log 2>/dev/null
if [ cat /tmp/uefi.log | grep -c ‘/dev/‘ -gt 0 ];then
for uefiline in cat /tmp/uefi.log
do
dd if=/dev/zero of=$uefiline bs=512 count=1
done
echo "delete os success"
elif [ cat /tmp/legacy.log | grep -c ‘/dev/‘ -gt 0 ];then
for legacyline in cat /tmp/legacy.log
do
dd if=/dev/zero of=$legacyline bs=10M count=1
done
echo "delete os success"
else
echo "delete os failed"
fi
}

deleteos

相关的ks配置文件

install
url --url=http://osinstall.idcos.com/centos7.5/
lang en_US.UTF-8
keyboard --vckeymap=us --xlayouts=‘us‘
network --bootproto=dhcp --device=eth0 --noipv6 --activate
rootpw --iscrypted $1$j2hVXk.y$r1lEzOe4mQFHn4/jfqJUv.

firewall --disabled
auth --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Shanghai --isUtc
text
reboot
zerombr
bootloader --location=mbr --append="console=tty0 net.ifnames=0 biosdevname=0 audit=0 selinux=0"
ignoredisk --only-use=sda
clearpart --all --initlabel
part /boot/efi --fstype=xfs --size=512
part biosboot --fstype=biosboot --size=1
part /boot --fstype=xfs --size=512
part pv.01 --size=20480 --grow --maxsize=102400
part pv.02 --size=10240 --grow --maxsize=204800
part pv.03 --size=1024 --grow
volgroup VolGroup00 --pesize=32768 pv.01 pv.02
logvol / --fstype=xfs --name=LVroot --vgname=VolGroup00 --size=20480
logvol /home --fstype=xfs --name=LVhome --vgname=VolGroup00 --size=5120
logvol /tmp --fstype=xfs --name=LVtmp --vgname=VolGroup00 --size=10240
logvol /var --fstype=xfs --name=LVvar --vgname=VolGroup00 --size=20480
logvol /opt --fstype=xfs --name=LVopt --vgname=VolGroup00 --size=30720
logvol swap --name=LVswap --vgname=VolGroup00 --size=5120

%packages --ignoremissing
et basebr/>@core
@development
tree
kernel-devel
gcc
screen
acpid
openssh-clients
rsync
vim
nano
wget
net-tools
tcpdump
bash-completion
chrony
ntpdate
%end

%pre
parted -s /dev/sda mklabel gpt
_sn=$(dmidecode -s system-serial-number 2>/dev/null | awk ‘/^[^#]/ { print $1 }‘)
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"Start Insatll OS program\",\"InstallProgress\":0.6,\"Sn\":\"$_sn\"}"
http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"System Patition and Install Packages\",\"InstallProgress\":0.7,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog

%end
%post --erroronfail --interpreter=/bin/bash
_sn=$(dmidecode -s system-serial-number 2>/dev/null | awk ‘/^[^#]/ { print $1 }‘)
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"Get parameter information\",\"InstallProgress\":0.8,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
curl --connect-timeout 60 -o /root/$_sn http://osinstall.idcos.com/parm/$_sn
curl --connect-timeout 60 -o /root/osinit_standard_pri.sh http://osinstall.idcos.com/parm/osinit_standard_pri.sh
chmod 777 /root/$_sn
chmod 777 /root/osinit_standard_pri.sh
hostname=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Hostname"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
os_ip=$(cat /root/$_sn |sed ‘s/,/\n/g‘|grep "Ip"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
gateway=$(cat /root/$_sn |sed ‘s/,/\n/g‘|grep "Gateway"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
netmasknum=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Netmasknum"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
mode=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Mode"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
vlan_id=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Vlan_id"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
netmode=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Netmode"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
securecheck=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Securecheck"|cut -d":" -f2|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
macaddress=$(cat /root/$_sn|sed ‘s/,/\n/g‘|grep "Macaddress"|cut -d":" -f2-20|sed -e ‘s/}//g‘ -e ‘s/"//g‘)
if [ -z "$hostname" -o -z "$os_ip" -o -z "$gateway" -o -z "$netmasknum" -o -z "$mode" -o -z "$vlan_id" -o -z "$netmode" -o -z "$securecheck" -o -z "$macaddress" ]
then
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"Parameter acquisition failed\",\"InstallProgress\":0.85,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
exit
fi
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"System initialization begins\",\"InstallProgress\":0.9,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
/bin/bash /root/osinit_standard_pri.sh $hostname $os_ip $gateway $netmasknum $mode $vlan_id $netmode $securecheck $macaddress &
if [ $? == 0 ]
then
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"System initialization finished\",\"InstallProgress\":1,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
else
curl -H "Content-Type: application/json" -X POST -d "{\"Title\":\"System initialization failed\",\"InstallProgress\":0.95,\"Sn\":\"$_sn\"}" http://osinstall.idcos.com:8083/api/osinstall/v1/report/deviceInstallLog
fi

%end

分享一个底层自动部署系统

标签:boot   machine   接收参数   fun   varchar   配置文件   删除   out   nis   

原文地址:https://blog.51cto.com/12768454/2501204

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!