Build pxe_server_install rpm from source

Change-Id: I5f39f6efd787df5ec21f81e52ba829efbdbeef5f
Signed-off-by: Zhijiang Hu <hu.zhijiang@zte.com.cn>
This commit is contained in:
Zhijiang Hu 2016-12-07 05:31:13 -05:00
parent 5e84308572
commit e6477591ac
50 changed files with 5511 additions and 3 deletions

View File

@ -0,0 +1,215 @@
{
//root
"root_pwd":"ossdbg1",
//M
"storage_size":"300000",
//G
"memory_size":"31",
//rootM
"root_lv_size":"51200",
//swapM
"swap_lv_size":"10240",
//dbM
"db_lv_size":"",
//mongodbM
"mongodb_lv_size":"",
//glance_M
"glance_lv_size":"",
//providerM
"provider_lv_size":"",
//novaM
"nova_lv_size":"",
//cinderM
"cinder_vg_size":"10240",
//dockerM
"docker_vg_size":"",
//
"disk_num":"1",
//
"root_disk":"sda",
//
"disk_list":"sda",
//
"reboot":"no",
//
"hugepages":"2",
//
"hugepagesize":"1G",
//1,21-4,6-8
"isolcpus":"",
//
"hostname":"bsp4_slot11",
//mount glanceyesfstab
"mount_glance":"no",
//tfg bin
"tfg_bin":"",
//pxemacpxedefault
"dhcp_mac":"24:52:00:83:03:46",
//iso
"iso_path":"/home/liushn/version/Mimosa-V02.16.11.P7B1I47-CGSL_VPLAT-5.1-x86_64-KVM/Mimosa-V02.16.11.P7B1I47-CGSL_VPLAT-5.1-x86_64-KVM.iso",
//
"group_list":"group_name1,base,group_name3",
// ifcfg-*
//
"interfaces": [
{
"name": "eth0",
"is_deployment": false,
"deleted": false,
// ip
"ip":"10.43.166.1",
"created_at": "2015-09-29T03:59:50.000000",
// slave2bond
"slave2": "ebl",
"updated_at": "2015-09-29T03:59:50.000000",
"mac": "00:07:e9:15:99:01",
//
"netmask":"255.255.255.0",
//
"gateway": "10.43.166.0",
"pci": "0000:11:00.0",
// slave1bond
"slave1": "",
// bond
"mode": "",
"assigned_networks": [
{
"capability": 200,
"physnet_name": "nttt",
"ip":"10.43.166.0",
"netmask":"255.255.255.0",
"gateway": "10.43.166.0",
"ml2_type": "vlan",
//typeetheripassigned_networks
//ipassigned_networkstypebondbond
"network_type": "MANAGEMENT"
}
],
"host_id": "9a07c5fe-71e9-425f-a281-0b129b6d9044",
"deleted_at": null,
//etherbond
"type": "ether",
"id": "191ca9a3-d330-4a6a-9975-e77a3d002b8e"
},
{
"name": "eth1",
"is_deployment": false,
"deleted": false,
"gateway":null ,
"created_at": "2015-09-29T03:59:50.000000",
"slave2": "ebl",
"updated_at": "2015-09-29T03:59:50.000000",
"mac": "12:23:34:57",
"ip":"192.168.0.5",
"netmask": "255.255.254.0",
"pci": "0000:04:00.0",
"slave1": "ebl",
"mode": "",
"assigned_networks": [
{
"capability": 200,
"physnet_name": "nttt",
"ip":"192.168.0.3",
"netmask":"255.255.255.0",
"gateway":"195.168.1.1",
"ml2_type": "vlan",
"network_type": "MANAGEMENT"
},
{
"capability": 200,
"physnet_name": "nttt",
"gateway": "10.43.166.2",
"ml2_type": "vlan",
"network_type": "ovs"
}
],
"host_id": "9a07c5fe-71e9-425f-a281-0b129b6d9044",
"deleted_at": null,
"type": "ether",
"id": "79eab777-e94e-4914-8741-65d765062626"
},
{
"name": "bond0",
"is_deployment": true,
"deleted": false,
"ip": "195.168.1.21",
"created_at": "2015-09-29T03:59:50.000000",
"slave2": "eth0",
"updated_at": "2015-09-29T03:59:50.000000",
"mac": "00:07:e9:15:99:00",
"netmask": "255.255.255.0",
"pci": "0000:10:00.1",
"slave1": "eth2",
"gateway": "10.43.166.1",
"mode": "1",
"assigned_networks": [
{
"capability": 200,
"physnet_name": "nttt",
"gateway": null,
"ml2_type": "vlan",
"network_type": "MANAGEMENT"
}
],
"host_id": "9a07c5fe-71e9-425f-a281-0b129b6d9044",
"deleted_at": null,
"type": "bond",
"id": "9a796f6b-1422-4e8c-ac97-c229250645ce"
},
{
"name": "eth2",
"is_deployment": true,
"deleted": false,
"ip": "195.168.1.21",
"created_at": "2015-09-29T03:59:50.000000",
"slave2": "ebl",
"updated_at": "2015-09-29T03:59:50.000000",
"mac": "00:07:e9:15:99:00",
"netmask": "255.255.255.0",
"gateway": "10.43.166.1",
"pci": "0000:10:00.0",
"slave1": "ebl",
"mode": "",
"assigned_networks": [
{
"capability": 200,
"physnet_name": "nttt",
"gateway": null,
"ml2_type": "vlan",
"network_type": "ovs"
}
],
"host_id": "9a07c5fe-71e9-425f-a281-0b129b6d9044",
"deleted_at": null,
"type": "ether",
"id": "9a796f6b-1422-4e8c-ac97-c229250645ce"
},
{
"name": "eth3",
"is_deployment": true,
"deleted": false,
"ip": "195.168.1.21",
"created_at": "2015-09-29T03:59:50.000000",
"slave2": "ebl",
"updated_at": "2015-09-29T03:59:50.000000",
"mac": "00:07:e9:15:99:00",
"netmask": "255.255.255.0",
"pci": "0000:10:00.1",
"slave1": "ebl",
"mode": "",
"assigned_networks": [
{
"capability": 200,
"physnet_name": "nttt",
"gateway": null,
"ml2_type": "vlan",
"network_type": "ovs"
}
],
"host_id": "9a07c5fe-71e9-425f-a281-0b129b6d9044",
"deleted_at": null,
"type": "ether",
"id": "9a796f6b-1422-4e8c-ac97-c229250645ce"
}
]
}

View File

@ -0,0 +1,14 @@
{
//pxe
"build_pxe":"yes",
//pxeDHCP
"ethname_l":"er3",
//pxeDHCPip
"ip_addr_l":"192.168.1.1",
//pxeDHCP
"net_mask_l":"255.255.255.0",
//pxeip
"client_ip_begin":"192.168.1.100",
//pxeip
"client_ip_end":"192.168.1.200"
}

View File

@ -0,0 +1,8 @@
default cgsl
prompt 10
timeout 20
# Install cgsl
label cgsl
kernel vmlinuz
ipappend 2
append ksdevice=bootif ks=nfs:192.170.0.1:/home/install_share/pxe_kickstart.cfg initrd=initrd.img text splash=silent showopts

View File

@ -0,0 +1,34 @@
ddns-update-style ad-hoc;
option space PXE;
option PXE.mtftp-ip code 1 = ip-address;
option PXE.mtftp-cport code 2 = unsigned integer 16;
option PXE.mtftp-sport code 3 = unsigned integer 16;
option PXE.mtftp-tmout code 4 = unsigned integer 8;
option PXE.mtftp-delay code 5 = unsigned integer 8;
option PXE.discovery-control code 6 = unsigned integer 8;
option PXE.discovery-mcast-addr code 7 = ip-address;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
option vendor-class-identifier "PXEClient";
vendor-option-space PXE;
option PXE.mtftp-ip 0.0.0.0;
filename "/pxelinux.0";
next-server 192.170.0.1;
}
ddns-update-style interim;
ignore client-updates;
default-lease-time 86400;
max-lease-time 604800;
shared-network 0 {
subnet 192.170.0.0 netmask 255.255.255.0 {
option routers 192.170.0.1;
option subnet-mask 255.255.255.0;
range 192.170.0.10 192.170.0.239;
}
}

View File

@ -0,0 +1,10 @@
[Unit]
Description=pxe iso
DefaultDependencies=no
[Mount]
What=/home/autoinstall/incomes/OPENCOS_CGSL.iso
Where=/linuxinstall
Type=iso9660
[Install]
WantedBy=local-fs.target

View File

@ -0,0 +1,285 @@
# Kickstart file automatically generated by anaconda.
install
nfs --server=192.170.0.1 --dir=iso_nfs_dir
lang en_US.UTF-8
keyboard us
text
rootpw ossdbg1
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc Asia/Shanghai
logging --host=192.170.0.1 --port=514 --level=debug
%include /tmp/part-include
zerombr
#bootloader --location=mbr --driveorder=sda
#####reboot
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
#clearpart --drives=sda --all
part /boot --fstype ext3 --size=400 --ondisk=sda
part biosboot --fstype=biosboot --size=1 --ondisk=sda
#LVM install
#end_part
volgroup vg_sys pv.01 --pesize=4096
volgroup cindervolumes pv.02 --pesize=4096
volgroup vg_docker pv.03 --pesize=4096
volgroup vg_data pv.04 --pesize=4096
logvol swap --fstype swap --vgname=vg_data --size=2000 --name=lv_swap
#lv_root
#lv_db
#lv_mongodb
#lv_glance_mount
#lv_nova
#vg_cinder
%packages --ignoremissing
@Core
glibc.i686
nss-softokn-freebl.i686
libgcc.i686
%end
%pre
#!/bin/sh
sleep 10
function lvm_clean()
{
#vg_rename
vgs_v_file=/tmp/vgs_v.txt
vgs -v > $vgs_v_file
lines=`cat $vgs_v_file |wc -l`
vg_name=`cat $vgs_v_file |awk '{print $1}'`
vg_name_arr=($vg_name)
vg_uuid=`cat $vgs_v_file |awk '{print $9}'`
vg_uuid_arr=($vg_uuid)
for (( i=1; i<$lines; i++ )); do
vgrename ${vg_uuid_arr[$i]} ${vg_name_arr[$i]}_$i
echo "vgrename ${vg_uuid_arr[$i]} ${vg_name_arr[$i]}_$i"
done
#remove lvs
lvscan_file=/tmp/lvscan.txt
lvscan > $lvscan_file
sed -i "s/'//g" $lvscan_file
lines=`cat $lvscan_file |wc -l`
lv_name=`cat $lvscan_file |awk '{print $2}'`
lv_name_arr=($lv_name)
for (( i=0; i<$lines; i++ )); do
lvchange -a n ${lv_name_arr[$i]}
lvremove ${lv_name_arr[$i]} -f
[[ `lvscan |grep -w "${lv_name_arr[$i]}"` == "" ]] && echo "lvchange -a n & lvremove ${lv_name_arr[$i]} success"
done
#remove vgs
vgs_file=/tmp/vgs.txt
vgs > $vgs_file
lines=`cat $vgs_file |wc -l`
vg_name=`cat $vgs_file |awk '{print $1}'`
vg_name_arr=($vg_name)
for (( i=1; i<$lines; i++ )); do
vgchange -a n ${vg_name_arr[$i]}
vgremove ${vg_name_arr[$i]} -f
[[ `vgs |grep -w "${vg_name_arr[$i]}"` == "" ]] && echo "vgchange -a n & vgremove ${vg_name_arr[$i]} success"
done
#remove pvs
pvs_file=/tmp/pvs.txt
pvs > $pvs_file
lines=`cat $pvs_file |wc -l`
pv_name=`cat $pvs_file |awk '{print $1}'`
pv_name_arr=($pv_name)
for (( i=1; i<$lines; i++ )); do
pvchange -a n ${pv_name_arr[$i]}
pvremove ${pv_name_arr[$i]} -f
[[ `pvs |grep -w "${pv_name_arr[$i]}"` == "" ]] && echo "pvchange -a n & pvremove ${pv_name_arr[$i]} success"
done
}
function part_clean()
{
disknamelist=sda
echo disknamelist=$disknamelist
disknamelist=`echo $disknamelist | sed "s/,/ /g"`
echo disknamelist=$disknamelist
disknamelist=($disknamelist)
for ((i=0;i<${#disknamelist[*]};i++))
do
echo i=$i
devname=`echo ${disknamelist[$i]}`
echo $devname
if [ -b /dev/$devname ];then
dev_part_list=""
dev_part_no=0
DEV_DISK=/dev/${devname}
dev_part_list=`ls /dev/${devname}[0-9] 2>/dev/null`
echo ${DEV_DISK} list: $dev_part_list
for j in $dev_part_list
do
if [[ -b $j ]]; then
dev_part_no="${j#*$devname}"
parted ${DEV_DISK} rm $dev_part_no -s
[ -b $j ] && echo "delete partion $j fail" || echo "delete partion $j success"
fi
done
fi
done
dev_list_last=`ls /dev/sd*`
echo dev_list_last=$dev_list_last
}
lvm_clean
part_clean
echo "#partitioning schem e generated in %pre for 2 drives" > /tmp/part-include
echo "bootloader --location=mbr --boot-drive=sda --driveorder=sda" >> /tmp/part-include
echo "clearpart --drives=sda --all" >> /tmp/part-include
%end
%post --nochroot
#!/bin/bash
INSTALL_SRC_ROOT=/mnt/isodir
LOCAL_DISK_ROOT=/mnt/sysimage
OS_INSTALL_SRC=$INSTALL_SRC_ROOT/os_install
OS_INSTALL_DST=$LOCAL_DISK_ROOT/home/os_install
OS_ISO_SRC=$INSTALL_SRC_ROOT/os_iso
OS_ISO_MOUNT_SRC=$INSTALL_SRC_ROOT/os_mount_iso
mkdir -p $OS_INSTALL_DST
#挂载源目录
NFS_SERVER_ADDRESS=192.170.0.1
[ ! -d $OS_INSTALL_SRC ] && { mkdir -p $OS_INSTALL_SRC; }
mount -o nolock $NFS_SERVER_ADDRESS:/home/install_share/macaddr $OS_INSTALL_SRC
[ ! -d $OS_ISO_SRC ] && { mkdir -p $OS_ISO_SRC; }
mount -o nolock $NFS_SERVER_ADDRESS:iso_nfs_dir $OS_ISO_SRC
mkdir -p $OS_ISO_MOUNT_SRC
mount -o loop -t iso9660 ${OS_ISO_SRC}/*.iso $OS_ISO_MOUNT_SRC
cp -f ${OS_INSTALL_SRC}/os.json ${OS_INSTALL_DST}/
cp -rf ${OS_INSTALL_SRC}/usrdata ${OS_INSTALL_DST}/
# copy bin file
cp -rf $OS_ISO_MOUNT_SRC/*.bin $OS_INSTALL_DST/
#zenic项目需求centos系统时保留iso源
if [ ! -e $OS_INSTALL_DST/*.bin ];then
OS_ISO_DST=$LOCAL_DISK_ROOT/var/tfg-sys/os_iso
mkdir -p $OS_ISO_DST
#copy iso to $OS_ISO_DST
cp -rf ${OS_ISO_MOUNT_SRC}/* ${OS_ISO_DST}/
fi
umount $OS_INSTALL_SRC
umount $OS_ISO_MOUNT_SRC
umount $OS_ISO_SRC
%end
%post
#!/bin/bash
#change network name and add vlan configuration
tmpline=`uuidgen`
tmpline=`echo $tmpline|tr -d '-'`
echo "$tmpline"> /etc/hostname
TFG_BIN=/home/os_install/*.bin
#lv_glance_nomount
#end lv_glance_nomount
#lv_provider_nomount
#end lv_provider_nomount
ssh-keygen -t rsa -P '' -f /root/.ssh/id_rsa
chmod 600 /root/.ssh/authorized_keys
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
REPO_ROUTE=/etc/yum.repos.d
[ ! -d ${REPO_ROUTE} ] && { mkdir -p ${REPO_ROUTE}; echo "create ${REPO_ROUTE}" >> /home/os_install/usrdata/pxe_install.log; }
rm -rf ${REPO_ROUTE}/*
if [ -e ${TFG_BIN} ]; then
systemctl enable httpd.service
systemctl start httpd.service
vgrename cindervolumes cinder-volumes
#sriov
systemctl restart sriov.service
systemctl disable superpathd.service
systemctl disable multipathd.service
chmod +x /etc/rc.d/rc.local
#config os
[ -e /usr/bin/opencosos-doctor.sh ] && { /usr/bin/opencosos-doctor.sh --auto; echo "os is cgslv5" >> /home/os_install/usrdata/pxe_install.log; }
if [ -e /usr/bin/doctor.sh ]; then
/usr/bin/doctor.sh --auto
echo "os is TFG" >> /home/os_install/usrdata/pxe_install.log
fi
#install TFG bin
if [ -e ${TFG_BIN} ]; then
export HOME=/root; chmod +x ${TFG_BIN}; ${TFG_BIN} install reboot=n; echo "${TFG_BIN} install reboot=n" >> /home/os_install/usrdata/pxe_install.log;
rm -rf ${TFG_BIN}
fi
#clean iptables
if [[ -e /usr/sbin/iptables ]]; then
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
service iptables save
fi
if [[ -e /etc/sysconfig/iptables ]]; then
sed -i "/reject-with/d" /etc/sysconfig/iptables
fi
systemctl disable iptables.service
systemctl disable ip6tables.service
#end clean iptables
else
#zenic项目需求centos系统时保留iso源
#create repos
REPO_FILE=${REPO_ROUTE}/OS_ISO.repo
[ ! -d ${REPO_ROUTE} ] && { mkdir -p ${REPO_ROUTE}; echo "create ${REPO_ROUTE}" >> /home/os_install/usrdata/pxe_install.log; }
rm -rf ${REPO_ROUTE}/*
touch ${REPO_FILE}
echo "[OS_ISO]" >${REPO_FILE}
echo "name=OS_ISO" >>${REPO_FILE}
echo "baseurl=file:/var/tfg-sys/os_iso" >>${REPO_FILE}
echo "enabled=1" >>${REPO_FILE}
echo "gpgcheck=0" >>${REPO_FILE}
fi
#nic fix
NIC_CFG=/home/os_install/usrdata/nic_net_cfg.sh
[ -e ${NIC_CFG} ] && { chmod +x ${NIC_CFG}; ${NIC_CFG}; echo "excute ${NIC_CFG}" >> /home/os_install/usrdata/pxe_install.log; }
#clear db_lv
[ -d /var/lib/mysql ] && { rm -rf /var/lib/mysql/*; echo "rm -rf /var/lib/mysql/*" >> /home/os_install/usrdata/pxe_install.log; }
#modify grubtool.cfg
GRUBTOOLCFG=/etc/grubtool.cfg
if [[ -e $GRUBTOOLCFG ]]; then
sed -i "s/^hugepage_size=.*/hugepage_size=\"pagevalue1\"/g" $GRUBTOOLCFG
sed -i "s/^hugepage_num=.*/hugepage_num=pagevalue2/g" $GRUBTOOLCFG
sed -i "s/^isolcpus=.*/isolcpus=\"isolvalue\"/g" $GRUBTOOLCFG
echo "modify /etc/grubtool.cfg & restart grubtool.service" >> /home/os_install/usrdata/pxe_install.log
fi
/bin/grubtool stop
sleep 30
%end

View File

@ -0,0 +1,18 @@
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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
}

Binary file not shown.

View File

@ -0,0 +1,341 @@
#!/bin/bash
ISO_MOUNT_DIR_NUM=10
ISO_NFS_TAB=/var/log/iso_nfs_tab.log
PXE_OS_TAB=/var/log/pxe_os_table.log
#######################
# 记录日志到/var/log/pxe_install.log
# $1:要记录的日志
# $2:如果值为console那么同时又在屏幕上打印此记录
# 这个函数的功能:记录一条检查日志,并在这个日志前面加上记录的时间
#######################
function pxelog
{
local LOGFILE=/var/log/pxe_install.log
if [ ! -f $LOGFILE ]; then
touch $LOGFILE
fi
#记录日志
LANG=en_US.ISO8859-1
echo -n `date '+%b %d %T'` >> $LOGFILE
echo -e " $1" >> $LOGFILE
[[ $2 = "console" ]] && echo -e "$1"
return 0
}
#######################
#从json配置文件读取参数
#######################
function get_config
{
local file=$1
local key=$2
[ ! -e $file ] && { pxelog "file ${file} not exit!!" "console"; return; }
config_answer=$(jq ".$key" $file | sed "s/\"//g" )
pxelog "${key}=$config_answer"
[[ "null" == ${config_answer} ]] && config_answer=""
#config_answer=$(echo $config_answer | sed "s/\"//g")
#忽略井号开头的注释行以及空行之后再grep过滤"key"所在的行
#local line=`sed '/^[[:space:]]*#/d' $file | sed /^[[:space:]]*$/d | grep -w "$key"| grep "$key[[:space:]]*="`
#if [ -z "$line" ]; then
# config_answer=""
#else
#将第一个=号替换为空格再删除第一个单词得到value
# config_answer=`echo $line | sed 's/=/ /' | sed -e 's/^\w*\ *//'`
#fi
}
#######################
#设置参数到conf配置文件
#######################
function set_config
{
local file=$1
local key=$2
local value=$3
[ ! -e $file ] && return
#echo update key $key to value $value in file $file ...
local exist=`grep "^[[:space:]]*[^#]" $file | grep -c "$key[[:space:]]*=[[:space:]]*.*"`
#注意:如果某行是注释,开头第一个字符必须是#号!!!
local comment=`grep -c "^[[:space:]]*#[[:space:]]*$key[[:space:]]*=[[:space:]]*.*" $file`
if [[ $value == "#" ]];then
if [ $exist -gt 0 ];then
sed -i "/^[^#]/s/$key[[:space:]]*=/\#$key=/" $file
fi
return
fi
if [ $exist -gt 0 ];then
#如果已经存在未注释的有效配置行直接更新value
sed -i "/^[^#]/s#$key[[:space:]]*=.*#$key=$value#" $file
elif [ $comment -gt 0 ];then
#如果存在已经注释掉的对应配置行则去掉注释更新value
sed -i "s@^[[:space:]]*#[[:space:]]*$key[[:space:]]*=[[:space:]]*.*@$key=$value@" $file
else
#否则在末尾追加有效配置行
#local timestamp=`env LANG=en_US.UTF-8 date`
#local writer=`basename $0`
echo "" >> $file
#echo "# added by $writer at $timestamp" >> $file
echo "$key=$value" >> $file
fi
}
function convert_mac_to_ip
{
local dhcp_mac=$1
local lease_file=/var/lib/dhcpd/dhcpd.leases
local line
local ip_addr
local log_postfix
install_log=""
#获取lease文件中最后出现这个mac地址的行号
line=`grep -n -wi "${dhcp_mac}" ${lease_file} |tail -n 1 |awk -F':' '{print $1}'`
[[ ${line} == "" ]] && { pxelog "pxe server did not assign an ip to this target machine";return 1; }
#找到这个行号之前最后一次出现的ip
ip_addr=`head -n ${line} ${lease_file} | grep -o '\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\>' |tail -n 1`
#用ip地址得到log日志文件名
install_log=/var/log/${ip_addr}
log_postfix=".log"
install_log=${install_log}${log_postfix}
pxelog "dhcp_mac=${dhcp_mac} MACADDR=${MACADDR} install_log=${install_log}!"
return 0
}
function repir_iso_nfs_number
{
local MACADDR=$1
local ISOMOUNTPATH=$2
local oper=$3
pxelog "starting repair $ISOMOUNTPATH used number in $ISO_NFS_TAB!"
(
flock -x 200
used_number=`cat $ISO_NFS_TAB |grep -w "${ISOMOUNTPATH}" | awk -F' ' '{print $2}' |head -n 1`
#判断used_number是否为数字
expr $used_number "+" 10 &> /dev/null
if [ $? -ne 0 ];then
pxelog "${ISOMOUNTPATH} used number is not a digital!" "console"
return 1
fi
pxelog "befor $oper ${MACADDR}, ${ISOMOUNTPATH} is used by $used_number nfs client!"
if [[ $oper == "add" ]]; then
((used_number=$used_number+1))
elif [[ $oper == "dec" ]]; then
if [[ $used_number -gt 0 ]]; then
((used_number=$used_number-1))
if [[ $used_number -eq 0 ]]; then
local linuxinstall_mount=`basename ${ISOMOUNTPATH}`
linuxinstall_mount="linuxinstall-""${linuxinstall_mount}"".mount"
systemctl disable $linuxinstall_mount &>/dev/null
systemctl stop $linuxinstall_mount &>/dev/null
umount -l ${ISOMOUNTPATH} &>/dev/null
fi
else
pxelog "[error]${ISOMOUNTPATH} is not mounted, cann't clean!"
return 1
fi
elif [[ $oper == "clean" ]]; then
if [[ $used_number -ne 0 ]]; then
used_number=0
fi
else
pxelog "repir_iso_nfs_number inputpara err: oper=$oper!"
fi
sed -i "s%${ISOMOUNTPATH} .*%${ISOMOUNTPATH} $used_number%g" $ISO_NFS_TAB
pxelog "after $oper ${MACADDR}, ${ISOMOUNTPATH} is used by $used_number nfs client!"
) 200>/var/log/iso_nfs_tab.lock
pxelog "started repair $ISOMOUNTPATH used number in $ISO_NFS_TAB!"
}
function clean_iso_nfs_number
{
local ISOMOUNTPATH
[[ ! -f $ISO_NFS_TAB ]] && return 0
pxelog "starting clean $ISO_NFS_TAB!"
(
flock -x 200
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
ISOMOUNTPATH=/linuxinstall/linuxinstall_$i
systemctl disable linuxinstall-linuxinstall_$i.mount &>/dev/null
systemctl stop linuxinstall-linuxinstall_$i.mount &>/dev/null
umount -l ${ISOMOUNTPATH} &>/dev/null
sed -i "s%${ISOMOUNTPATH} .*%${ISOMOUNTPATH} 0%g" $ISO_NFS_TAB
done
) 200>/var/log/iso_nfs_tab.lock
pxelog "started to clean $ISO_NFS_TAB!"
}
function clean_os_files
{
local MACADDR=$1
local OS_TABLE=$2
local linuxinstall_dir=""
#删除/home/install_share、/tftpboot下和目标机相关的东西
rm /home/install_share/${MACADDR} -rf
rm /tftpboot/${MACADDR} -rf
rm /tftpboot/pxelinux.cfg/01-${MACADDR} -rf
#将这个目标机使用的iso mount路径的使用数减一如果减到0了则umount
[[ -f $OS_TABLE ]] && { linuxinstall_dir=`cat $OS_TABLE | grep -wi "$MACADDR" |awk -F' ' '{print $4}'`; }
if [[ `echo $linuxinstall_dir |grep "/linuxinstall/linuxinstall_*"` != "" ]]; then
repir_iso_nfs_number $MACADDR $linuxinstall_dir "dec"
local newlog=`cat $OS_TABLE | grep -wi "$MACADDR" |sed "s%$linuxinstall_dir%null%g"`
sed -i "s%$MACADDR.*%$newlog%g" $OS_TABLE
else
pxelog "[info]$MACADDR does not have a iso nfs dir or $OS_TABLE not exist!"
fi
}
function clean_all_os_files
{
#删除/home/install_share、/tftpboot下所有目标机相关的东西
rm /home/install_share/* -rf
if [[ -d /tftpboot ]]; then
mkdir -p /tftpboot_bak
cp -rf /tftpboot/* /tftpboot_bak/
rm -rf /tftpboot/*
cp /tftpboot_bak/initrd.img /tftpboot/
cp /tftpboot_bak/pxelinux.0 /tftpboot/
cp /tftpboot_bak/vmlinuz /tftpboot/
cp -rf /tftpboot_bak/pxelinux.cfg /tftpboot/
rm -rf /tftpboot/pxelinux.cfg/01-*
rm -rf /tftpboot_bak
fi
#将所有/linuxinstall/linuxinstall_n的路径umount使用数也清0
clean_iso_nfs_number
}
function clean_os_table
{
local MACADDR=$1
local OS_TABLE=$2
if [ -f ${OS_TABLE} ]; then
[[ `cat ${OS_TABLE} |grep "${MACADDR}"` != "" ]] && sed -i "/${MACADDR}/d" ${OS_TABLE}
fi
}
#清除某个目标机使用过的所有ip的日志
function clean_mac_all_log
{
local dhcp_mac=$1
local lease_file=/var/lib/dhcpd/dhcpd.leases
local line_mac
local ip_addr
local log_postfix
install_log_tmp=""
#获取lease文件中是否出现这个mac地址
list=`grep -n -wi "${dhcp_mac}" ${lease_file} |awk -F':' '{print $1}'`
[[ ${list} == "" ]] && { pxelog "pxe server did not assign an ip to this target machine";return 1; }
#如果lease文件中是否出现这个mac地址则删除这一项
for i in $list
do
#找到出现这个mac地址所在的行号
line_mac=$i
#找到这个行号之前最后一次出现的ip
line=`head -n ${line_mac} ${lease_file} | grep -n -o '\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\>' |tail -n 1`
ip_addr=`echo $line |awk -F':' '{print $2}'`
#用ip地址得到log日志文件名并且清除日志
install_log_tmp=/var/log/${ip_addr}
log_postfix=".log"
install_log_tmp=${install_log_tmp}${log_postfix}
if [[ ${install_log_tmp} != "" ]]; then
INSTALL_LOG_TMP=${install_log_tmp}
if [ -f ${INSTALL_LOG_TMP} ]; then
echo > ${INSTALL_LOG_TMP}
pxelog "clean_mac_all_log dhcp_mac=${dhcp_mac} MACADDR=${MACADDR} install_log_tmp=${install_log_tmp} clean ${install_log_tmp}!"
else
pxelog "clean_mac_all_log dhcp_mac=${dhcp_mac} MACADDR=${MACADDR} install_log_tmp=${install_log_tmp} not exist!"
fi
fi
done
return 0
}
#清除所有目标机使用过的所有ip的日志
function clean_all_log
{
local lease_file=/var/lib/dhcpd/dhcpd.leases
local ip_addr
local log_postfix
install_log_tmp=""
[[ ! -f $lease_file ]] && return 0
#获取lease文件中所有分配出去的ip
list=`cat $lease_file |grep -o '\<[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\>'`
[[ ${list} == "" ]] && { pxelog "pxe server did not assign an ip to any target machine";return 1; }
#如果lease文件中是否出现这个mac地址则删除这一项
for i in $list
do
ip_addr=$i
#用ip地址得到log日志文件名并且清除日志
install_log_tmp=/var/log/${ip_addr}
log_postfix=".log"
install_log_tmp=${install_log_tmp}${log_postfix}
if [[ ${install_log_tmp} != "" ]]; then
INSTALL_LOG_TMP=${install_log_tmp}
if [ -f ${INSTALL_LOG_TMP} ]; then
echo > ${INSTALL_LOG_TMP}
pxelog "clean_all_log install_log_tmp=${install_log_tmp} clean ${install_log_tmp}!"
else
pxelog "clean_all_log install_log_tmp=${install_log_tmp} not exist!"
fi
fi
done
return 0
}
#清除某个目标机最后使用的ip的日志
function clean_mac_last_log
{
local dhcp_mac=$1
convert_mac_to_ip ${dhcp_mac} || { return 1; }
INSTALL_LOG=${install_log}
if [ -f ${INSTALL_LOG} ]; then
echo > $INSTALL_LOG
pxelog "clean_mac_last_log dhcp_mac=${dhcp_mac} MACADDR=${MACADDR} install_last_log=${INSTALL_LOG} clean ${INSTALL_LOG}!"
else
pxelog "clean_mac_last_log dhcp_mac=${dhcp_mac} MACADDR=${MACADDR} install_last_log=${INSTALL_LOG} not exist!"
fi
return 0
}

View File

@ -0,0 +1,104 @@
#! /bin/bash
WORKDIR=/etc/pxe_install
source $WORKDIR/scripts/common.sh
source $WORKDIR/scripts/interface.sh
PXE_CFG=$2
#准备工作安装json文件解析工具jq包
rpm -qi jq >/dev/null
[ $? -ne 0 ] && rpm -ivh ${WORKDIR}/pxe/jq-1.3-2.el7.x86_64.rpm
#准备和清理文件夹
# 创建/linuxinstall以及清除里面的内容
systemctl disable linuxinstall.mount &>/dev/null
systemctl stop linuxinstall.mount &>/dev/null
umount -l /linuxinstall &>/dev/null
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
[ ! -d /linuxinstall/linuxinstall_$i ] && mkdir -p /linuxinstall/linuxinstall_$i
systemctl disable linuxinstall-linuxinstall_$i.mount &>/dev/null
systemctl stop linuxinstall-linuxinstall_$i.mount &>/dev/null
umount -l /linuxinstall/linuxinstall_$i &>/dev/null
rm -rf /linuxinstall/linuxinstall_$i/* &>/dev/null
done
# 创建/home/install_share以及清除里面的内容
[ ! -d /home/install_share ] && mkdir -p /home/install_share
rm -rf /home/install_share/* 2>/dev/null
# 创建/tftpboot以及清除里面的内容
[ ! -d /tftpboot ] && mkdir /tftpboot
rm -rf /tftpboot/* 2>/dev/null
# 设置dhcp服务端ip地址
pxelog "set dhcp ip..." "console"
#set_svrip $WORKDIR/pxe/pxe_env.conf
set_svrip $PXE_CFG
# 安装pxe服务器组件
pxelog "install pxe..." "console"
PXE_FILE_PATH=$WORKDIR/pxe
install_pxe $PXE_FILE_PATH
# 网络文件共享
pxelog "config nfs..." "console"
systemctl stop nfs
# 查看/etc/exports是否有#注释标记,如果有的话,则进行清理
install_share_dir=`cat /etc/exports | grep /home/install_share | grep \#`
[ -n "$install_share_dir" ] && sed -i "\/home\/install_share/d" /etc/exports
tftpboot_dir=`cat /etc/exports | grep /tftpboot | grep \#`
[ -n "$tftpboot_dir" ] && sed -i "\/tftpboot/d" /etc/exports
linuxinstall_dir=`cat /etc/exports | grep /linuxinstall | grep \#`
[ -n "$linuxinstall_dir" ] && sed -i "\/linuxinstall/d" /etc/exports
linuxinstall_dir=`cat /etc/exports | grep -w "/linuxinstall "`
[ -n "$linuxinstall_dir" ] && sed -i "\/linuxinstall/d" /etc/exports
#/* 启动文件共享 */
[ `cat /etc/exports | grep -c /home/install_share` -eq 0 ] && { echo "/home/install_share *(rw,no_root_squash)">> /etc/exports; } \
|| { sed -i "s%/home/install_share.*%/home/install_share *(rw,no_root_squash)%g" /etc/exports; }
[ `cat /etc/exports | grep -c /tftpboot` -eq 0 ] && { echo "/tftpboot *(ro)" >> /etc/exports; } \
|| { sed -i "s%/tftpboot.*%/tftpboot *(ro)%g" /etc/exports; }
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
[ `cat /etc/exports | grep -c -w "/linuxinstall/linuxinstall_$i"` -eq 0 ] && { echo "/linuxinstall/linuxinstall_$i *(ro)" >> /etc/exports; } \
|| { sed -i "s%\/linuxinstall\/linuxinstall_$i .*%\/linuxinstall\/linuxinstall_$i *(ro)%g" /etc/exports; }
done
#创建一张表格存放10个iso的nfs路径以及当前被使用的次数
rm -f $ISO_NFS_TAB &>/dev/null
touch $ISO_NFS_TAB
echo "iso_mount_point used" >>$ISO_NFS_TAB
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
echo "/linuxinstall/linuxinstall_$i 0" >>$ISO_NFS_TAB
done
# 拷贝ISO中的引导程序到根目录
if [ -f "$WORKDIR/ramdisk/initrd.img" ]; then
cp -f $WORKDIR/ramdisk/initrd.img /tftpboot/
fi
if [ -f "$WORKDIR/ramdisk/vmlinuz" ]; then
cp -f $WORKDIR/ramdisk/vmlinuz /tftpboot/
fi
cp -f /usr/share/syslinux/pxelinux.0 /tftpboot/
# 定制pxe配置文件包括ks文件. 修改的文件路径:/home/install_share/pxe_kickstart.cfg
#custom_pxecfg $WORKDIR/pxe/pxe_env.conf
custom_pxecfg $PXE_CFG
#启动pxe服务器
start_pxesvr

View File

@ -0,0 +1,18 @@
##此脚本用来一键式执行/home/opencos_install/after目录下的shell脚本
##将脚本用户shell脚本文件放入/home/usrdata/目录下,执行./after.sh就可以执行所有/home/opencos_install/after脚本
GUARD_DIR=/home/opencos_install/custom/after
[ ! -d $GUARD_DIR ] && exit 0
cd $GUARD_DIR
ALL_FILE=`ls $GUARD_DIR|grep .sh$`
RETVAL=
for FILE in $ALL_FILE
do
chmod +x $FILE
bash $FILE
RETVAL=$?
done
rpm -qi openstack-neutron-openvswitch >/dev/null && sed -i "/after.sh/d" /etc/rc.d/rc.local && sed -i "/sleep 30/d" /etc/rc.d/rc.local

View File

@ -0,0 +1,39 @@
#!/bin/bash
function update_vnc_ip
{
local nova_config="/etc/nova/nova.conf"
local vncip=$1
if [ "$vncip" != "" -a -f $nova_config ];then
tmp_ip=`openstack-config --get $nova_config DEFAULT "vncserver_proxyclient_address"`
if [ "$tmp_ip" = "127.0.0.1" ];then
openstack-config --set $nova_config DEFAULT "vncserver_proxyclient_address" $vncip
systemctl restart openstack-nova-compute.service
fi
fi
}
function do_matching
{
ipaddr=""
netmask=""
device=""
gateway=`grep manage_bond_gateway ../custom.conf|awk -F '=' '{print $2}'`
local nic_gate=""
local num=`grep manage_eth_vlan_num ../custom.conf |awk -F '=' '{print $2}'`
local linux_bond=`grep manage_bond_name ../custom.conf|awk -F '=' '{print $2}'`
local vlan=0
local i=1
while [ $i -le $num ]
do
vlan=`grep "eth_vlan_id$i" ../custom.conf|awk -F '=' '{print $2}'`
device=$linux_bond"."$vlan
nic_gate=`grep ^GATEWAY /etc/sysconfig/network-scripts/ifcfg-$device|awk -F '=' '{print $2}'`
if [ $nic_gate -a $nic_gate = $gateway ];then
ipaddr=`grep ^IPADDR /etc/sysconfig/network-scripts/ifcfg-$device|awk -F '=' '{print $2}'`
netmask=`grep ^NETMASK /etc/sysconfig/network-scripts/ifcfg-$device|awk -F '=' '{print $2}'`
break
fi
let "i+=1"
done
update_vnc_ip $ipaddr
}
do_matching

View File

@ -0,0 +1,237 @@
#!/bin/bash
if [ ! "$_CREATE_BOND_FILE" ];then
_CREATE_BOND_DIR=`pwd`
cd $_CREATE_BOND_DIR
#读取配置文件参数
function get_config
{
local file="$1"
local key="$2"
#配置文件不存在,错误
[ ! -f "$file" ] && { echo -e "\n$file not exist."; return 0; }
local key_num=`cat $file |sed '/^[[:space:]]*#/d' |sed -n "1,/\[]/p" |grep -w "$key[[:space:]]*" |grep -c "$key[[:space:]]*="`
#模块中没有配置该key
[ "$key_num" -eq 0 ] && return 0
#一个key有多个值错误
[ "$key_num" -gt 1 ] && { echo -e "\nthere are too many \"$key\" in $file"; return 0; }
local key_line=`cat $file|sed '/^[[:space:]]*#/d' |sed -n "1,/\[]/p"|grep -w "$key[[:space:]]*"|grep "$key[[:space:]]*="|tr -d ["\n"] |tr -d ["\r"]`
if [ "$key_line" != "" ];then
config_answer=`echo $key_line |awk -F'=' '{print $2}'`
else
echo -e "\nthere is no line inclued \"$key=\" in $file"
return 0
fi
return 0
}
function make_bond
{
local CUSTOM_CFG_FILE=$1
local num
local i=1
local j=1
local bri=1
local phynic=""
local mtu=""
local pci=""
first=""
second=""
bond_mode=""
phyname=""
device=""
bond_name=""
bridge=""
brdata=""
get_config $CUSTOM_CFG_FILE "ovs-port-bond_num"
num=$config_answer
while [ $i -le $num ]
do
echo "make ovs_bond$i" >> /var/tmp/data_bond.log
brdata=`cat /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini |grep ^bridge_mappings|awk -F ':' '{print $2}'`
ovs-vsctl del-br $brdata
if [ $i -eq 1 ];then
get_config $CUSTOM_CFG_FILE "ovs_port_uplink_port$i"
config_answer=${config_answer//,/ }
first=`echo $config_answer |awk '{print $1}'`
second=`echo $config_answer |awk '{print $2}'`
get_config $CUSTOM_CFG_FILE "ovs_port_bond_mode$i"
if [[ "$config_answer" = "0" ]];then
bond_mode="active-backup;off"
elif [[ "$config_answer" = "1" ]];then
bond_mode="balance-slb;off"
else
bond_mode="balance-tcp;active"
fi
get_config $CUSTOM_CFG_FILE "ovs_phynet_name$i"
phyname=$config_answer
get_config $CUSTOM_CFG_FILE "ovs_bridge_name$i"
bridge="$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS bridge_mappings "$bridge"
get_config $CUSTOM_CFG_FILE "ovs_bond_name$i"
bond_name=$config_answer
phynic="$phyname:$bond_name($bond_mode;$first-$second)"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS phynic_mappings "$phynic"
get_config $CUSTOM_CFG_FILE "ovs_mtu_mappings$i"
mtu="$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS mtu_mappings "$mtu"
systemctl restart neutron-openvswitch-agent.service
# ovs-vsctl add-port "br-data$bri" "bond$bri"
let "i+=1"
let "bri+=1"
else
get_config $CUSTOM_CFG_FILE "ovs_port_uplink_port$i"
config_answer=${config_answer//,/ }
first=`echo $config_answer |awk '{print $1}'`
second=`echo $config_answer |awk '{print $2}'`
get_config $CUSTOM_CFG_FILE "ovs_port_bond_mode$i"
if [[ "$config_answer" = "0" ]];then
bond_mode="active-backup;off"
elif [[ "$config_answer" = "1" ]];then
bond_mode="balance-slb;off"
else
bond_mode="balance-tcp;active"
fi
get_config $CUSTOM_CFG_FILE "ovs_phynet_name$i"
phyname=$config_answer
get_config $CUSTOM_CFG_FILE "ovs_bridge_name$i"
bridge=$bridge",$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS bridge_mappings "$bridge"
get_config $CUSTOM_CFG_FILE "ovs_bond_name$i"
bond_name=$config_answer
phynic=$phynic",$phyname:$bond_name($bond_mode;$first-$second)"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS phynic_mappings "$phynic"
get_config $CUSTOM_CFG_FILE "ovs_mtu_mappings$i"
mtu=$mtu",$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS mtu_mappings "$mtu"
systemctl restart neutron-openvswitch-agent.service
# ovs-vsctl add-port "br-data$bri" "bond$bri"
let "i+=1"
let "bri+=1"
fi
done
get_config $CUSTOM_CFG_FILE "sriov-port-bond_num"
num=$config_answer
while [ $j -le $num ]
do
echo "make sriov_bond$j" >>/var/tmp/data_bond.log
if [ $j -eq 1 ];then
get_config $CUSTOM_CFG_FILE "sriov_phynet_name$j"
phyname=$config_answer
get_config $CUSTOM_CFG_FILE "sriov_port_uplink_port$j"
config_answer=${config_answer//,/ }
first=`echo $config_answer |awk '{print $1}'`
second=`echo $config_answer |awk '{print $2}'`
pci="{ \"address\":\"`ethtool -i $first|grep bus-info|awk '{printf $2}'`\",\"physical_network\":\"$phyname\" }"
pci=$pci",{ \"address\":\"`ethtool -i $second|grep bus-info|awk '{printf $2}'`\",\"physical_network\":\"$phyname\" }"
openstack-config --set /etc/nova/nova.conf DEFAULT pci_passthrough_whitelist "[$pci]"
get_config $CUSTOM_CFG_FILE "sriov_port_bond_mode$j"
if [[ "$config_answer" = "0" ]];then
bond_mode="active-backup;off"
elif [[ "$config_answer" = "1" ]];then
bond_mode="balance-slb;off"
else
bond_mode="balance-tcp;active"
fi
get_config $CUSTOM_CFG_FILE "sriov_bridge_name$j"
bridge="$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC bridge_mappings "$bridge"
get_config $CUSTOM_CFG_FILE "sriov_bond_name$j"
bond_name=$config_answer
phynic="$phyname:$bond_name($bond_mode;$first-$second)"
device="$phyname:$first-$second"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC physical_device_mappings "$device"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC phynic_mappings "$phynic"
openstack-config --set /etc/nova/nova.conf DEFAULT phynic_mappings "$phynic"
get_config $CUSTOM_CFG_FILE "sriov_mtu_mappings$j"
mtu="$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC mtu_mappings "$mtu"
systemctl restart openstack-nova-compute.service
systemctl restart neutron-sriov-nic-switch-agent.service
# ovs-vsctl add-port "br-data$bri" "bond$bri"
let "bri+=1"
let "j+=1"
else
get_config $CUSTOM_CFG_FILE "sriov_phynet_name$j"
phyname=$config_answer
get_config $CUSTOM_CFG_FILE "sriov_port_uplink_port$j"
config_answer=${config_answer//,/ }
first=`echo $config_answer |awk '{print $1}'`
second=`echo $config_answer |awk '{print $2}'`
pci=$pci",{ \"address\":\"`ethtool -i $first|grep bus-info|awk '{printf $2}'`\",\"physical_network\":\"$phyname\" }"
pci=$pci",{ \"address\":\"`ethtool -i $second|grep bus-info|awk '{printf $2}'`\",\"physical_network\":\"$phyname\" }"
openstack-config --set /etc/nova/nova.conf DEFAULT pci_passthrough_whitelist "[$pci]"
get_config $CUSTOM_CFG_FILE "sriov_port_bond_mode$j"
if [[ "$config_answer" = "0" ]];then
bond_mode="active-backup;off"
elif [[ "$config_answer" = "1" ]];then
bond_mode="balance-slb;off"
else
bond_mode="balance-tcp;active"
fi
get_config $CUSTOM_CFG_FILE "sriov_bridge_name$j"
bridge=$bridge",$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC bridge_mappings "$bridge"
get_config $CUSTOM_CFG_FILE "sriov_bond_name$j"
bond_name=$config_answer
phynic=$phynic",$phyname:$bond_name($bond_mode;$first-$second)"
device=$device",$phyname:$first-$second"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC physical_device_mappings "$device"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC phynic_mappings "$phynic"
openstack-config --set /etc/nova/nova.conf DEFAULT phynic_mappings "$phynic"
get_config $CUSTOM_CFG_FILE "sriov_mtu_mappings$j"
mtu=$mtu",$phyname:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC mtu_mappings "$mtu"
systemctl restart openstack-nova-compute.service
systemctl restart neutron-sriov-nic-switch-agent.service
# ovs-vsctl add-port "br-data$bri" "bond$bri"
let "j+=1"
let "bri+=1"
fi
done
}
function do_install
{
local CUSTOM_CFG_FILE="../custom.conf"
config_answer=""
get_config $CUSTOM_CFG_FILE "data_port_is_using_bonding"
if [ $config_answer = "no" ];then
echo "not make_bond" >>/var/tmp/data_bond.log
get_config $CUSTOM_CFG_FILE "data_port_phynic"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS phynic_mappings "physnet1:$config_answer"
openstack-config --set /etc/neutron/plugins/openvswitch/ovs_neutron_plugin.ini OVS bridge_mappings "physnet1:br-data1"
systemctl restart neutron-openvswitch-agent.service
get_config $CUSTOM_CFG_FILE "data_port_phynic"
openstack-config --set /etc/nova/nova.conf DEFAULT pci_passthrough_whitelist "[{ \"address\":\"`ethtool -i $config_answer|grep bus-info|awk '{printf $2}'`\",\"physical_network\":\"physnet1\" }]"
openstack-config --set /etc/nova/nova.conf DEFAULT phynic_mappings "physnet1:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC bridge_mappings "physnet1:br-data1"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC physical_device_mappings "physnet1:$config_answer"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC mtu_mappings "physnet1:1520"
openstack-config --set /etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini SRIOV_NIC phynic_mappings "physnet1:$config_answer"
systemctl restart openstack-nova-compute.service
systemctl restart neutron-sriov-nic-switch-agent.service
else
make_bond $CUSTOM_CFG_FILE
echo "data_bond make successful" >>/var/tmp/data_bond.log
fi
}
touch /var/tmp/data_bond.log
echo "start do_install" >>/var/tmp/data_bond.log
do_install
_CREATE_BOND_FILE="create_bond_sh"
fi

View File

@ -0,0 +1,5 @@
#!/bin/bash
chmod +x moni_port/*
\cp -rf moni_port/* /usr/bin
sed -i "/moni_port_status/d" /etc/rc.d/rc.local && echo "[ -f /usr/bin/moni_port_status ] && /usr/bin/moni_port_status start" >> /etc/rc.d/rc.local
/usr/bin/moni_port_status start

View File

@ -0,0 +1,5 @@
#!/bin/bash
chmod +x nova_compute_mem_moni/*
\cp -rf nova_compute_mem_moni/* /usr/bin
sed -i "/nova_compute_mem_moni/d" /etc/rc.d/rc.local && echo "[ -f /usr/bin/nova_compute_mem_moni.py ] && /usr/bin/python /usr/bin/nova_compute_mem_moni.py start" >> /etc/rc.d/rc.local
/usr/bin/python /usr/bin/nova_compute_mem_moni.py start

View File

@ -0,0 +1,236 @@
#!/usr/bin/python
import time
import sys
import argparse
import logging
import random
import fcntl
import os
import pwd
import grp
import sys
import signal
import resource
import logging
import atexit
from logging import handlers
class Daemonize(object):
""" Daemonize object
Object constructor expects three arguments:
- app: contains the application name which will be sent to syslog.
- pid: path to the pidfile.
- action: your custom function which will be executed after daemonization.
- keep_fds: optional list of fds which should not be closed.
- auto_close_fds: optional parameter to not close opened fds.
- privileged_action: action that will be executed before drop privileges if user or
group parameter is provided.
If you want to transfer anything from privileged_action to action, such as
opened privileged file descriptor, you should return it from
privileged_action function and catch it inside action function.
- user: drop privileges to this user if provided.
- group: drop privileges to this group if provided.
- verbose: send debug messages to logger if provided.
- logger: use this logger object instead of creating new one, if provided.
"""
def __init__(self, app, pid, action, keep_fds=None, auto_close_fds=True, privileged_action=None, user=None, group=None, verbose=False, logger=None):
self.app = app
self.pid = pid
self.action = action
self.keep_fds = keep_fds or []
self.privileged_action = privileged_action or (lambda: ())
self.user = user
self.group = group
self.logger = logger
self.verbose = verbose
self.auto_close_fds = auto_close_fds
def sigterm(self, signum, frame):
""" sigterm method
These actions will be done after SIGTERM.
"""
self.logger.warn("Caught signal %s. Stopping daemon." % signum)
os.remove(self.pid)
sys.exit(0)
def exit(self):
""" exit method
Cleanup pid file at exit.
"""
#self.logger.warn("Stopping daemon.")
pf = file(self.pid, 'r')
pid = int(pf.read().strip())
pf.close()
os.kill(pid, signal.SIGTERM)
os.remove(self.pid)
sys.exit(0)
def start(self):
""" start method
Main daemonization process.
"""
# If pidfile already exists, we should read pid from there; to overwrite it, if locking
# will fail, because locking attempt somehow purges the file contents.
if os.path.isfile(self.pid):
with open(self.pid, "r") as old_pidfile:
old_pid = old_pidfile.read()
# Create a lockfile so that only one instance of this daemon is running at any time.
try:
lockfile = open(self.pid, "w")
except IOError:
print("Unable to create the pidfile.")
sys.exit(1)
try:
# Try to get an exclusive lock on the file. This will fail if another process has the file
# locked.
fcntl.flock(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
print("Unable to lock on the pidfile.")
# We need to overwrite the pidfile if we got here.
with open(self.pid, "w") as pidfile:
pidfile.write(old_pid)
sys.exit(1)
# Fork, creating a new process for the child.
process_id = os.fork()
if process_id < 0:
# Fork error. Exit badly.
sys.exit(1)
elif process_id != 0:
# This is the parent process. Exit.
sys.exit(0)
# This is the child process. Continue.
# Stop listening for signals that the parent process receives.
# This is done by getting a new process id.
# setpgrp() is an alternative to setsid().
# setsid puts the process in a new parent group and detaches its controlling terminal.
process_id = os.setsid()
if process_id == -1:
# Uh oh, there was a problem.
sys.exit(1)
# Add lockfile to self.keep_fds.
self.keep_fds.append(lockfile.fileno())
# Close all file descriptors, except the ones mentioned in self.keep_fds.
devnull = "/dev/null"
if hasattr(os, "devnull"):
# Python has set os.devnull on this system, use it instead as it might be different
# than /dev/null.
devnull = os.devnull
if self.auto_close_fds:
for fd in range(3, resource.getrlimit(resource.RLIMIT_NOFILE)[0]):
if fd not in self.keep_fds:
try:
os.close(fd)
except OSError:
pass
devnull_fd = os.open(devnull, os.O_RDWR)
os.dup2(devnull_fd, 0)
os.dup2(devnull_fd, 1)
os.dup2(devnull_fd, 2)
if self.logger is None:
# Initialize logging.
self.logger = logging.getLogger(self.app)
self.logger.setLevel(logging.DEBUG)
# Display log messages only on defined handlers.
self.logger.propagate = False
# Initialize syslog.
# It will correctly work on OS X, Linux and FreeBSD.
if sys.platform == "darwin":
syslog_address = "/var/run/syslog"
else:
syslog_address = "/dev/log"
# We will continue with syslog initialization only if actually have such capabilities
# on the machine we are running this.
if os.path.isfile(syslog_address):
syslog = handlers.SysLogHandler(syslog_address)
if self.verbose:
syslog.setLevel(logging.DEBUG)
else:
syslog.setLevel(logging.INFO)
# Try to mimic to normal syslog messages.
formatter = logging.Formatter("%(asctime)s %(name)s: %(message)s",
"%b %e %H:%M:%S")
syslog.setFormatter(formatter)
self.logger.addHandler(syslog)
# Set umask to default to safe file permissions when running as a root daemon. 027 is an
# octal number which we are typing as 0o27 for Python3 compatibility.
os.umask(0o27)
# Change to a known directory. If this isn't done, starting a daemon in a subdirectory that
# needs to be deleted results in "directory busy" errors.
os.chdir("/")
# Execute privileged action
privileged_action_result = self.privileged_action()
if not privileged_action_result:
privileged_action_result = []
# Change gid
if self.group:
try:
gid = grp.getgrnam(self.group).gr_gid
except KeyError:
self.logger.error("Group {0} not found".format(self.group))
sys.exit(1)
try:
os.setgid(gid)
except OSError:
self.logger.error("Unable to change gid.")
sys.exit(1)
# Change uid
if self.user:
try:
uid = pwd.getpwnam(self.user).pw_uid
except KeyError:
self.logger.error("User {0} not found.".format(self.user))
sys.exit(1)
try:
os.setuid(uid)
except OSError:
self.logger.error("Unable to change uid.")
sys.exit(1)
try:
lockfile.write("%s" % (os.getpid()))
lockfile.flush()
except IOError:
self.logger.error("Unable to write pid to the pidfile.")
print("Unable to write pid to the pidfile.")
sys.exit(1)
# Set custom action on SIGTERM.
signal.signal(signal.SIGTERM, self.sigterm)
atexit.register(self.exit)
self.logger.warn("Starting daemon.")
self.action(*privileged_action_result)
def main():
os.system("/usr/bin/moni_port_status.sh")
pid = "/tmp/moni_port.pid"
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.propagate = False
fh = logging.FileHandler("/tmp/moni_port.log", "w")
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
keep_fds = [fh.stream.fileno()]
daemon = Daemonize(app="moni_port", pid=pid, action=main, keep_fds=keep_fds)
daemon.start()
if __name__ == "__main__":
sys.exit(main())

View File

@ -0,0 +1,248 @@
#!/bin/bash
logfile="/var/log/monitor_port"
sriov_conf=/etc/sriov.conf
sriov_agent_conf=/etc/neutron/plugins/sriovnicagent/sriov_nic_plugin.ini
sriov_chang_vf_status=/home/opencos_install/custom/after/moni_port/nic_update
function do_logfile
{
rm -rf $logfile
touch $logfile
echo "##this is monitor port logfile" >>$logfile
}
#记录日志
function do_log
{
local logstr=$1
LANG=en_US.ISO8859-1
echo -n `date '+%b %d %T'` >> $logfile
echo " $logstr" >>$logfile
}
vm_ids=""
function monitor_port
{
check_sriov_config
ret=`echo $?`
do_log "check_sriov_config $ret"
if [ $ret -ne 0 ] ; then
#check_sriov_bond
#ret=`echo $?`
#do_log "check_sriov_bond $ret"
#if [ $ret -ne 0 ] ; then
#do_log "sriov_bond_check"
#sriov_monitor_port
#fi
do_log "sriov_bond_check"
sriov_monitor_port
else
do_log "macvtap_check"
macvtap_monitor_port
fi
}
function check_sriov_config
{
echo "check sriov config runing"
check_file_exist $sriov_conf
[ "$exist" = "no" ] && return 0
check_head_str_exist $sriov_conf "sriov_vnic_type = direct"
[ "$exist" != "" ] && return 1
return 0
}
#目前就只支持主背模式
function check_sriov_bond
{
do_log "check sriov bond runing"
check_file_exist $sriov_agent_conf
[ "$exist" = "no" ] && return 0
check_str_exist $sriov_agent_conf "active-backup"
[ "$exist" != "" ] && return 1
return 0
}
function check_head_str_exist
{
local file=$1
local str="$2"
exist=`cat $file | grep -w "^[[:space:]]*$str"`
}
function check_str_exist
{
local file=$1
local str="$2"
exist=`cat $file | grep -v "#" | grep $str`
}
#判断文件是否存在
function check_file_exist
{
exist="no"
local file=$1
if [ -f $file ];then
exist="yes"
else
do_log "$file: file doesn't exist"
fi
}
function sriov_monitor_port
{
local phynic_bond_up=""
local phynic_bond_down=""
local phynic_bond_down_last=""
local phynic_bond_up_last=""
check_file_exist $sriov_agent_conf
[ "$exist" = "no" ] && return 0
chmod +x $sriov_chang_vf_status
while true
do
phynic_bond_up=`ovs-appctl bond/show | grep -B 2 "active slave" | grep ":" | awk '{print $2}'| sed 's/://g'`
if [ ! $phynic_bond_up ] ; then
phynic_bond_down=`ovs-appctl bond/show | grep "slave " | awk '{print $2}' | sed 's/://g'`
else
phynic_bond_down=`ovs-appctl bond/show | grep "slave " | awk '{print $2}' | sed 's/://g' | grep -v $phynic_bond_up`
fi
if [[ $phynic_bond_up != $phynic_bond_up_last ]] ; then
for i in $phynic_bond_up
do
do_log "$i:need to up"
check_sriov_active $i
done
fi
if [[ $phynic_bond_down != $phynic_bond_down_last ]] ; then
for i in $phynic_bond_down
do
do_log "$i: need to down"
check_sriov_down $i
done
fi
phynic_bond_down_last=$phynic_bond_down
phynic_bond_up_last=$phynic_bond_up
sleep 2
done
}
function check_sriov_active
{
local up_port_name=$1
check_str_exist $sriov_agent_conf $up_port_name
[ "$exist" = "" ] && return 1
$sriov_chang_vf_status $up_port_name UP $logfile
}
function check_sriov_down
{
local down_port_name=$1
check_str_exist $sriov_agent_conf $down_port_name
[ "$exist" = "" ] && return 1
port_stat=`ip link show efr | awk -F"state|mode" '{print $2}'`
if [ "$port_stat" = "UP" ] ; then
$sriov_chang_vf_status $down_port_name DOWN $logfile
fi
}
function macvtap_monitor_port
{
local macvtap_port_source=""
local macvtap_port_name=""
while true
do
do_logfile
vm_ids=`virsh list | sed -e '/^$/d' -e '/^#/d' | sed '1,2d' | awk '{print $1}' |tr '\n' ' '`
do_log "vm_ids: $vm_ids"
for var in $vm_ids
do
do_log "Vm instance id:$var"
vm_macvtap_ports=`virsh domiflist $var | sed '1,2d' | awk '{print $1":"$3}' | grep "macvtap" |tr '\n' ' '`
for vm_macvtap_port in $vm_macvtap_ports
do
do_log "$vm_macvtap_port"
macvtap_port_source=`echo "$vm_macvtap_port" | awk -F ':' '{print $2}'`
macvtap_port_name=`echo "$vm_macvtap_port" | awk -F ':' '{print $1}'`
update_macvtap_port_status $macvtap_port_source $macvtap_port_name
done
done
sleep 2
done
}
function update_macvtap_port_status
{
local macvtap_port_source=$1
local macvtap_port_name=$2
if [ "$macvtap_port_source" != "" ]; then
macvtap_port_vf_pci=`ethtool -i $macvtap_port_source |grep 'bus-info' | awk '{print $2}'`
do_log "macvtap_port_vf_pci:$macvtap_port_vf_pci"
fi
if [ "$macvtap_port_vf_pci" != "" ]; then
macvtap_port_pf_name=`ls /sys/bus/pci/devices/$macvtap_port_vf_pci/physfn/net/`
do_log "macvtap_port_pf_name:$macvtap_port_pf_name"
fi
if [ "$macvtap_port_pf_name" != "" ]; then
macvtap_port_pf_status=`ethtool $macvtap_port_pf_name | grep 'Link detected' | awk -F ': ' '{print $2}'`
do_log "macvtap_port_pf_status:$macvtap_port_pf_status"
fi
if [ "$macvtap_port_pf_status" != "" ]; then
if [ $macvtap_port_pf_status = "no" ]; then
virsh domif-setlink $var $macvtap_port_name down
else
set_macvtap_port_status $var $macvtap_port_pf_name $macvtap_port_name
fi
fi
}
function set_macvtap_port_status
{
local var=$1
local pf_name=$2
local macvtap_port_name=$3
local type=""
local bond_name=""
local state=""
do_log "pf_name: $pf_name"
type=`ovs-appctl bond/list |sed '1d' |grep $pf_name | awk '{print $2}'`
bond_name=`ovs-appctl bond/list |sed '1d' |grep $pf_name | awk '{print $1}'`
if [ "$type" != "" ]; then
do_log "type: $type"
if [ "$type" != "active-backup" ]; then
virsh domif-setlink $var $macvtap_port_name up
else
state=`ovs-appctl bond/show $bond_name |awk "/$pf_name/ {getline; print}" |grep active`
do_log "state: $state"
if [ "$state" != "" ]; then
virsh domif-setlink $var $macvtap_port_name up
else
virsh domif-setlink $var $macvtap_port_name down
fi
fi
else
virsh domif-setlink $var $macvtap_port_name up
fi
do_log `virsh domif-getlink $var $macvtap_port_name`
}
monitor_port

View File

@ -0,0 +1,106 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/if.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
#define PRIVATE_SETVF 0x03
#define VF_UP 0x01
#define VF_DOWN 0x00
#define SUCCESS 0
#define SIOCDEVPRIINFO 0x89FE
#define MAXLEN 1024
FILE *logfile = NULL;
/* for passing single values */
struct private_value{
unsigned int cmd;
unsigned int data;
};
static send_ioctl(const char* ifname, struct private_value *pval)
{
struct ifreq ifr;
int fd, ret;
/* Setup our control structures. */
strcpy(ifr.ifr_name, ifname);
/* Open control socket. */
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
fputs("socket FAIL\n", logfile);
return -1;
}
ifr.ifr_data = (caddr_t)pval;
ret = ioctl(fd, SIOCDEVPRIINFO, &ifr);
if(ret)
{
close(fd);
fputs("ioctl FAIL\n", logfile);
return -1;
}
close(fd);
return 0;
}
static SendMsgToVF(char* ifname, struct private_value *pval)
{
int ret;
ret = send_ioctl(ifname,pval);
return ret;
}
int main(int argc, char *argv[])
{
unsigned char buf[MAXLEN];
struct private_value vf_data;
memset(&vf_data,0,sizeof(vf_data));
if ((argv[1] == NULL) || (argv[2] == NULL) || (argv[3] == NULL))
{
exit(1);
}
logfile = fopen(argv[3], "ab+" );
if(logfile == NULL)
{
printf("%s, %s",argv[3],"not exit\n");
exit(1);
}
// Ö±½ÓÉèÖÃ
vf_data.cmd = PRIVATE_SETVF;
if ((0 == strcmp(argv[2], "UP"))||(0 == strcmp(argv[2], "up")))
{
vf_data.data = VF_UP;
fprintf(logfile, "need to make %s up\n", argv[1]);
}
else if ((0 == strcmp(argv[2], "DOWN"))||(0 == strcmp(argv[2], "down")))
{
vf_data.data = VF_DOWN;
fprintf(logfile, "need to make %s down\n", argv[1]);
}
else
{
fputs("wrong vf status\n", logfile);
fclose(logfile);
return -1;
}
if(SUCCESS != SendMsgToVF(argv[1], &vf_data))
{
fclose(logfile);
logfile = NULL;
return -1;
}
fclose(logfile);
logfile = NULL;
return 0;
}

View File

@ -0,0 +1,19 @@
##此脚本用来一键式执行/home/opencos_install/目录下的shell脚本
##将脚本用户shell脚本文件放入/home/opencos_install/目录下,执行./before.sh就可以执行所有/home/opencos_install/脚本的脚本
GUARD_DIR=/home/opencos_install/custom/before
[ ! -d $GUARD_DIR ] && exit 0
cd $GUARD_DIR
ALL_FILE=`ls $GUARD_DIR|grep .sh$`
RETVAL=
for FILE in $ALL_FILE
do
chmod +x $FILE
bash $FILE
RETVAL=$?
done
echo before>>/var/log/log.txt
[ $RETVAL -eq 0 ] && sed -i "/before.sh/d" /etc/rc.d/rc.local

View File

@ -0,0 +1,370 @@
#!/bin/bash
if [ ! "$_CREATE_MANAGER_PORT_FILE" ];then
_CREATE_MANAGER_PORT_FILE_DIR=`pwd`
cd $_CREATE_MANAGER_PORT_FILE_DIR
function get_config
{
local file="$1"
local key="$2"
#配置文件不存在,错误
[ ! -f "$file" ] && { echo -e "\n$file not exist."; return 0; }
local key_num=`cat $file |sed '/^[[:space:]]*#/d' |sed -n "1,/\[]/p" |grep -w "$key[[:space:]]*" |grep -c "$key[[:space:]]*="`
#模块中没有配置该key
[ "$key_num" -eq 0 ] && return 0
#一个key有多个值错误
[ "$key_num" -gt 1 ] && { echo -e "\nthere are too many \"$key\" in $file"; return 0; }
local key_line=`cat $file|sed '/^[[:space:]]*#/d' |sed -n "1,/\[]/p"|grep -w "$key[[:space:]]*"|grep "$key[[:space:]]*="|tr -d ["\n"] |tr -d ["\r"]`
if [ "$key_line" != "" ];then
config_answer=`echo $key_line |awk -F'=' '{print $2}'`
else
echo -e "\nthere is no line inclued \"$key=\" in $file"
return 0
fi
return 0
}
function get_netmask
{
local num=`echo $config_answer|awk -F '/' '{print $2}'`
local i=0
netma="255"
let "num-=8"
while [ $i -lt 3 ]
do
if [ $num -ge 8 ];then
let "num-=8"
netma=$netma".255"
elif [ $num -eq 0 ];then
let "num-=0"
netma=$netma".0"
elif [ $num -eq 7 ];then
let "num-=7"
netma=$netma".254"
elif [ $num -eq 6 ];then
let "num-=6"
netma=$netma".252"
elif [ $num -eq 5 ];then
let "num-=5"
netma=$netma".248"
elif [ $num -eq 4 ];then
let "num-=4"
netma=$netma".240"
elif [ $num -eq 3 ];then
let "num-=3"
netma=$netma".224"
elif [ $num -eq 2 ];then
let "num-=2"
netma=$netma".192"
elif [ $num -eq 1 ];then
let "num-=1"
netma=$netma".128"
fi
let "i+=1"
done
}
function get_gateway
{
local ip1=$1
local ip2=$2
local ne=$3
local gw1=""
local gw2=""
local a1=""
local a2=""
local b=""
local i=1
while [ $i -lt 5 ]
do
a1=`echo $ip1|awk -F "." '{print $'$i'}'`
a2=`echo $ip2|awk -F "." '{print $'$i'}'`
b=`echo $ne|awk -F "." '{print $'$i'}'`
gw1=`echo $(( $a1 & $b))`
gw2=`echo $(( $a2 & $b))`
if [ $gw1 -ne $gw2 ];then
return 1
fi
let "i+=1"
done
return 0
}
function constitute_bin
{
local bin_num1=`echo ${#hci_bin}`
local bin_num2=`echo ${#dhcp_bin}`
local i=8
local j=8
while [ $i -gt $bin_num1 ]
do
hci_bin="0""$hci_bin"
let "i-=1"
done
while [ $j -gt $bin_num2 ]
do
dhcp_bin="0""$dhcp_bin"
let "j-=1"
done
}
function constitute_ip
{
local hci_ip=$1
local dhcp_ip=$2
local num=`echo $config_answer|awk -F '/' '{print $2}'`
local hci_str1=`echo $hci_ip|awk -F '.' '{print $1}'`
local hci_str2=`echo $hci_ip|awk -F '.' '{print $2}'`
local hci_str3=`echo $hci_ip|awk -F '.' '{print $3}'`
local hci_str4=`echo $hci_ip|awk -F '.' '{print $4}'`
local dhcp_str1=`echo $dhcp_ip|awk -F '.' '{print $1}'`
local dhcp_str2=`echo $dhcp_ip|awk -F '.' '{print $2}'`
local dhcp_str3=`echo $dhcp_ip|awk -F '.' '{print $3}'`
local dhcp_str4=`echo $dhcp_ip|awk -F '.' '{print $4}'`
local hci_num1=`expr $num / 8`
local hci_num2=`expr $num % 8`
local split_num=`expr 1 + $hci_num1`
hci_bin=""
dhcp_bin=""
local bin=""
local ten=""
if [ $split_num -eq 1 ];then
hci_bin=`echo "obase=2;$hci_str1"|bc`
dhcp_bin=`echo "obase=2;$dhcp_str1"|bc`
constitute_bin
hci_bin=`echo ${hci_bin:0:$hci_num2}`
dhcp_bin=`echo ${dhcp_bin:$hci_num2:8}`
bin="$hci_bin""$dhcp_bin"
((ten=2#$bin))
ipadd="$ten.""$dhcp_str2.""$dhcp_str3.""$dhcp_str4"
elif [ $split_num -eq 2 ];then
hci_bin=`echo "obase=2;$hci_str2"|bc`
dhcp_bin=`echo "obase=2;$dhcp_str2"|bc`
constitute_bin
hci_bin=`echo ${hci_bin:0:$hci_num2}`
dhcp_bin=`echo ${dhcp_bin:$hci_num2:8}`
bin="$hci_bin""$dhcp_bin"
((ten=2#$bin))
ipadd="$hci_str1.""$ten.""$dhcp_str3.""$dhcp_str4"
elif [ $split_num -eq 3 ];then
hci_bin=`echo "obase=2;$hci_str3"|bc`
dhcp_bin=`echo "obase=2;$dhcp_str3"|bc`
constitute_bin
hci_bin=`echo ${hci_bin:0:$hci_num2}`
dhcp_bin=`echo ${dhcp_bin:$hci_num2:8}`
bin="$hci_bin""$dhcp_bin"
((ten=2#$bin))
ipadd="$hci_str1.""$hci_str2.""$ten.""$dhcp_str4"
elif [ $split_num -eq 4 ];then
hci_bin=`echo "obase=2;$hci_str4"|bc`
dhcp_bin=`echo "obase=2;$dhcp_str4"|bc`
constitute_bin
hci_bin=`echo ${hci_bin:0:$hci_num2}`
dhcp_bin=`echo ${dhcp_bin:$hci_num2:8}`
bin="$hci_bin""$dhcp_bin"
((ten=2#$bin))
ipadd="$hci_str1.""$hci_str2.""$hci_str3.""$ten"
fi
}
function vlan_eth_create
{
local CUSTOM_CFG_FILE=$1
local vlan_eth_name=""
local vlan_id=""
local gw=""
local mode=""
netma=""
ipadd=""
local num=""
local i=1
get_config $CUSTOM_CFG_FILE "install_mode"
mode=$config_answer
get_config $CUSTOM_CFG_FILE "install_type"
typ=$config_answer
get_config $CUSTOM_CFG_FILE "manage_bond_gateway"
gw=$config_answer
get_config $CUSTOM_CFG_FILE "manage_eth_vlan_num"
num=$config_answer
while [ $i -le $num ]
do
get_config $CUSTOM_CFG_FILE "eth_vlan_ip$i"
ipadd=`echo $config_answer|awk -F '/' '{print $1}'`
if [ $mode = "compute" -o $typ = "pxe" ];then
#ipadd=`echo ${ipadd%.*}`"."`echo ${ipaddr##*.} `
constitute_ip $ipadd $ipaddr
fi
get_netmask
get_config $CUSTOM_CFG_FILE "eth_vlan_id$i"
vlan_id=$config_answer
vlan_eth_name="$linux_bond.$vlan_id"
# ip link add link $linux_bond name $vlan_eth_name type vlan id $vlan_id
# ifconfig $vlan_eth_name $ipadd
touch /etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "DEVICE=$vlan_eth_name" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "IPADDR=$ipadd" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "NETMASK=$netma" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
echo "VLAN=yes" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
get_gateway $ipadd $gw $netma
if [ $? -eq 0 ];then
echo "GATEWAY=$gw" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
fi
# sed '$a\ip link add link '$linux_bond' name '$vlan_eth_name' type vlan id '$vlan_id'' -i /etc/rc.local
# sed '$a\ifup '$vlan_eth_name'' -i /etc/rc.local
let "i+=1"
done
}
function get_ip_eth
{
ipaddr=`cat /etc/sysconfig/network-scripts/ifcfg-$bond_eth1 | grep "^[[:space:]]*[^#]"|grep IPADDR |awk -F '=' '{print $2}'|tr -d '"'`
netmask=`cat /etc/sysconfig/network-scripts/ifcfg-$bond_eth1 |grep "^[[:space:]]*[^#]"|grep NETMASK |awk -F '=' '{print $2}'|tr -d '"'`
#网卡配置文件里面读不到IP 可能是DHCP方式获取ifconfig获取
if [[ -z $ipaddr ]]; then
ipaddr=`ifconfig $bond_eth1 |grep 'inet addr' | awk '{print $2}'`
ipaddr=`echo $ipaddr | awk -F ':' '{print $2}'`
fi
if [[ -z $ipaddr ]]; then
ipaddr=`ifconfig $bond_eth1 |grep 'inet ' | awk '{print $2}'`
fi
if [[ -z $netmask ]]; then
netmask=`ifconfig $bond_eth1 |grep 'Mask' | awk '{print $4}'`
netmask=`echo $netmask | awk -F ':' '{print $2}'`
fi
if [[ -z $netmask ]]; then
netmask=`ifconfig $bond_eth1 |grep 'netmask' | awk '{print $4}'`
fi
if [[ -z $ipaddr ]]; then
ipaddr=`cat /etc/sysconfig/network-scripts/ifcfg-$bond_eth2 | grep "^[[:space:]]*[^#]"|grep IPADDR |awk -F '=' '{print $2}'|tr -d '"'`
netmask=`cat /etc/sysconfig/network-scripts/ifcfg-$bond_eth2 |grep "^[[:space:]]*[^#]"|grep NETMASK |awk -F '=' '{print $2}'|tr -d '"'`
fi
if [[ -z $ipaddr ]]; then
ipaddr=`ifconfig $bond_eth2 |grep 'inet addr' | awk '{print $2}'`
ipaddr=`echo $ipaddr | awk -F ':' '{print $2}'`
fi
if [[ -z $ipaddr ]]; then
ipaddr=`ifconfig $bond_eth2 |grep 'inet ' | awk '{print $2}'`
fi
if [[ -z $netmask ]]; then
netmask=`ifconfig $bond_eth2 |grep 'Mask' | awk '{print $4}'`
netmask=`echo $netmask | awk -F ':' '{print $2}'`
fi
if [[ -z $netmask ]]; then
netmask=`ifconfig $bond_eth2 |grep 'netmask' | awk '{print $4}'`
fi
gateway=`route |grep default |awk '{print $2}'`
}
function eth_update
{
local str=`find /etc/sysconfig/network-scripts/ -name "ifcfg-*"`
local eth=""
local i=1
local key_num=""
local eth_name=""
while true
do
eth=`echo $str|awk '{print $'$i'}'`
key_num=`cat $eth |sed '/^[[:space:]]*#/d' |sed -n "1,/\[]/p" |grep -w "DEVICE[[:space:]]*" |grep -c "DEVICE[[:space:]]*="`
if [ $key_num -eq 0 ];then
eth_name=`echo $eth |awk -F - '{print $3}'`
sed '$i\DEVICE='$eth_name'' -i $eth
fi
sed -i "/BOOTPROTO/s/dhcp/static/" $eth
sed -i "/ONBOOT/s/no/yes/" $eth
if [ $eth = `echo $str|awk '{print $NF}'` ];then
break;
fi
let "i+=1"
done
}
function make_linux_bond
{
local CUSTOM_CFG_FILE=$1
get_config $CUSTOM_CFG_FILE "manage_bond_name"
linux_bond=$config_answer
eth_update
# ip link add $linux_bond type bond
ifdown $bond_eth1
ifdown $bond_eth2
touch /etc/sysconfig/network-scripts/ifcfg-$linux_bond
echo "DEVICE=$linux_bond" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
echo "BONDING_OPTS=\"mode=1 miimon=100\"" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
# echo "IPADDR=$ipaddr" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
# echo "NETMASK=$netmask" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
# echo "GATEWAY=$gateway" >>/etc/sysconfig/network-scripts/ifcfg-$linux_bond
sed '$a\MASTER='$linux_bond'' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
sed '$a\SLAVE=yes' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
sed -i "/BOOTPROTO/s/static/none/" /etc/sysconfig/network-scripts/ifcfg-$bond_eth1
sed '$a\MASTER='$linux_bond'' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
sed '$a\SLAVE=yes' -i /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
sed -i "/BOOTPROTO/s/static/none/" /etc/sysconfig/network-scripts/ifcfg-$bond_eth2
# route add default gw $gateway dev $linux_bond
if [ -f "/etc/modprobe.d/bonding.conf" ];then
touch /etc/modprobe.d/bonding.conf
fi
echo "alias $linux_bond bonding" >>/etc/modprobe.d/bonding.conf
echo "options $linux_bond miimon=100 mode=1" >> /etc/modprobe.d/bonding.conf
modprobe bonding
echo "modprobe bonding" >>/etc/rc.local
ifup $bond_eth1
ifup $bond_eth2
ifdown $linux_bond
ifup $linux_bond
vlan_eth_create $CUSTOM_CFG_FILE
systemctl restart network
}
function do_install
{
ipaddr=""
netmask=""
gateway=""
local CUSTOM_CFG_FILE="../custom.conf"
config_answer=""
get_config $CUSTOM_CFG_FILE "manage_port_is_using_bonding"
if [ $config_answer = "yes" ];then
get_config $CUSTOM_CFG_FILE "manage_port_uplink_port"
config_answer=${config_answer//,/ }
bond_eth1=`echo $config_answer |awk '{print $1}'`
bond_eth2=`echo $config_answer |awk '{print $2}'`
get_config $CUSTOM_CFG_FILE "install_type"
if [ $config_answer = "usb" ];then
dhclient $bond_eth1
sleep 10
fi
get_ip_eth
make_linux_bond $CUSTOM_CFG_FILE
sleep 30
fi
}
do_install
_CREATE_MANAGER_PORT_FILE="create_manager_port_bond.sh"
fi

View File

@ -0,0 +1,64 @@
[install-configure]
install_type=pxe
install_mode=compute
[manage-configure]
manage_port_is_using_bonding=yes
manage_port_bond_mode=active-backup
manage_port_uplink_port=enp129s0f0,enp129s0f1
manage_port_dhcp_enable=disable
manage_eth_vlan_num=2
manage_bond_name=bond0
manage_bond_gateway=192.168.1.1
[eth_vlan1]
eth_vlan_ip1=
eth_vlan_id1=
[eth_vlan2]
eth_vlan_ip2=
eth_vlan_id2=
[data-configure]
data_port_is_using_bonding=yes
data_port_phynic=er0
sriov-port-bond_num=3
ovs-port-bond_num=3
[sriov-port-bond1]
sriov_port_bond_mode1=1
sriov_port_uplink_port1=enp145s0f1,enp145s0f0
sriov_mtu_mappings1=1520
sriov_phynet_name1=physnet4
sriov_bridge_name1=br-bond4
sriov_bond_name1=bond4
[sriov-port-bond2]
sriov_port_bond_mode2=2
sriov_port_uplink_port2=enp145s0f1,enp145s0f0
sriov_mtu_mappings2=1520
sriov_phynet_name2=physnet5
sriov_bridge_name2=br-bond5
sriov_bond_name2=bond5
[sriov-port-bond3]
sriov_port_bond_mode3=1
sriov_port_uplink_port3=enp110s0f0,enp110s0f1
sriov_mtu_mappings3=1520
sriov_phynet_name3=physnet6
sriov_bridge_name3=br-bond6
sriov_bond_name3=bond6
[ovs-port-bond1]
ovs_port_bond_mode1=1
ovs_port_uplink_port1=enp155s0f0,enp155s0f1
ovs_mtu_mappings1=1520
ovs_phynet_name1=physnet1
ovs_bridge_name1=br-bond1
ovs_bond_name1=bond1
[ovs-port-bond2]
ovs_port_bond_mode2=0
ovs_port_uplink_port2=enp143s0f0,enp143s0f1
ovs_mtu_mappings2=1520
ovs_phynet_name2=physnet2
ovs_bridge_name2=br-bond2
ovs_bond_name2=bond2
[ovs-port-bond3]
ovs_port_bond_mode3=2
ovs_port_uplink_port3=enp112s0f0,enp112s0f1
ovs_mtu_mappings3=1520
ovs_phynet_name3=physnet3
ovs_bridge_name3=br-bond3
ovs_bond_name3=bond3

View File

@ -0,0 +1,19 @@
#! /bin/bash
###################################################################################
# 询问与安装系统OS/OPENCOS相关的配置参数
# 入口interact_setup
# 各模块的交互脚本放在/custom/interact/目录下,并在此interfact()添加调用脚本函数
###################################################################################
export WORKDIR
source $WORKDIR/scripts/custom/interact/neutron_interact.sh
#交互函数
function interfact()
{
local CUSTOM_CFG_FILE=$1
ask_manage_bond $CUSTOM_CFG_FILE $2
ask_virtualization_mechanism $CUSTOM_CFG_FILE
}

View File

@ -0,0 +1,669 @@
#! /bin/bash
###################################################################################
# 询问与安装系统OS/OPENCOS相关的配置参数
# 入口interact_setup
#
###################################################################################
#设置是否需要做控制面bond
function ask_manage_bond
{
local CUSTOM_CFG_FILE=$1
local install_type=$2
echo ""
echo -e ">>client machine manage port use bonding ,yes or no[default no]: \c"
read parm
[[ ! -z `echo $parm |grep -iwE "y|yes"` ]] && parm=yes
[[ ! -z `echo $parm |grep -iwE "n|no"` ]] && parm=no
case $parm in
"yes")
set_config $CUSTOM_CFG_FILE "manage_port_is_using_bonding" "yes"
ask_manage_bond_port_name $CUSTOM_CFG_FILE $install_type
echo
;;
"no")
set_config $CUSTOM_CFG_FILE "manage_port_is_using_bonding" "no"
echo
;;
"")
set_config $CUSTOM_CFG_FILE "manage_port_is_using_bonding" "no"
echo
;;
*)
echo "Please input yes or no"
ask_manage_bond $CUSTOM_CFG_FILE
;;
esac
}
#确定哪些网口需要bond处理
function ask_manage_bond_port_name
{
local CUSTOM_CFG_FILE=$1
local install_type=`cat $2|grep install_type|awk -F '=' '{print $2}'`
set_config $CUSTOM_CFG_FILE "install_type" "$install_type"
num=""
local net=""
local bond_uplink_port=""
if [ $install_type = "pxe" ];then
get_netmask_num $2
fi
echo ""
echo -e ">>Which type of node would you install,control or compute [default:compute]:\c"
read parm5
while true
do
if [[ -z $parm5 ]];then
parm5="compute"
break
elif [ $parm5 = "control" -o $parm5 = "compute" ];then
break
else
echo ""
echo -e ">>The input is not legitimate,please re-enter [default:compute]:\c"
read parm5
fi
done
set_config $CUSTOM_CFG_FILE "install_mode" "$parm5"
echo ""
echo "Manage port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name[default:eth0,eth1]: \c"
read parm
if [[ -z $parm ]];then
bond_uplink_port="eth0,eth1"
else
bond_uplink_port=$parm
fi
bond_eth[99]=`echo $parm|awk -F , '{print $1}'`
bond_eth[100]=`echo $parm|awk -F , '{print $2}'`
set_config $CUSTOM_CFG_FILE "manage_port_uplink_port" "$bond_uplink_port"
set_config $CUSTOM_CFG_FILE "manage_port_bond_mode" "active-backup"
set_config $CUSTOM_CFG_FILE "manage_port_dhcp_enable" "disable"
echo ""
echo -e ">>Enter the vlan subinterface1 ip [default: 192.168.1.0/24]: \c"
read parm1
if [[ -z $parm1 ]];then
parm1="192.168.1.X/24"
fi
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
while true
do
if [ $net ];then
expr $net "+" 10 &> /dev/null
if [ $? -eq 0 ];then
if [ $net -eq $num ];then
break
else
echo "The netmask does not belong to the initialization of dhcp server "
fi
else
echo "The input is wrong"
fi
else
echo "The input can not be empty"
fi
echo -e ">>Please input the correct ip: \c"
read parm1
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
done
set_config $CUSTOM_CFG_FILE "eth_vlan_ip1" "$parm1"
echo ""
echo -e ">>Enter the vlan_id of the vlan subinterface1 : \c"
read parm2
set_config $CUSTOM_CFG_FILE "eth_vlan_id1" "$parm2"
echo ""
echo -e ">>Enter the vlan subinterface2 ip [default: 192.169.1.0/24]: \c"
read parm1
if [[ -z $parm1 ]];then
parm1="192.169.1.X/24"
fi
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
while true
do
if [ $net ];then
expr $net "+" 10 &> /dev/null
if [ $? -eq 0 ];then
if [ $net -eq $num ];then
break
else
echo "The netmask does not belong to the initialization of dhcp server "
fi
else
echo "The input is wrong"
fi
else
echo "The input can not be empty"
fi
echo -e ">>Please input the correct ip: \c"
read parm1
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
done
set_config $CUSTOM_CFG_FILE "eth_vlan_ip2" "$parm1"
echo ""
echo -e ">>Enter the vlan_id of the vlan subinterface2 : \c"
read parm2
set_config $CUSTOM_CFG_FILE "eth_vlan_id2" "$parm2"
echo ""
echo "Would you like to make more vlan subinterface"
echo -e ">>Please input an number[default:0]: \c"
read parm3
if [[ -z $parm3 ]];then
parm3=0
fi
let "parm3+=2"
set_config $CUSTOM_CFG_FILE "manage_eth_vlan_num" "$parm3"
local i=3
while [ $i -le $parm3 ]
do
echo "[eth_vlan$i]" >> $CUSTOM_CFG_FILE
echo ""
echo -e ">>Enter the vlan subinterface$i ip [example: 192.169.1.0/24]: \c"
read parm1
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
while true
do
if [ $net ];then
expr $net "+" 10 &> /dev/null
if [ $? -eq 0 ];then
if [ $net -eq $num ];then
break
else
echo "The netmask does not belong to the initialization of dhcp server "
fi
else
echo "The input is wrong"
fi
else
echo "The input can not be empty"
fi
echo -e ">>Please input the correct ip: \c"
read parm1
net=`echo $parm1|awk -F '/' '{print $2}'`
if [ $install_type = "usb" ];then
num=$net
fi
done
set_config $CUSTOM_CFG_FILE "eth_vlan_ip$i" "$parm1"
echo ""
echo -e ">>Enter the vlan_id of the vlan subinterface$i : \c"
read parm2
set_config $CUSTOM_CFG_FILE "eth_vlan_id$i" "$parm2"
let "i+=1"
done
echo ""
echo -e ">>Which vlan subinterface would you like to choose as gateway ,please input the gateway :\c"
read parm4
set_config $CUSTOM_CFG_FILE "manage_bond_gateway" "$parm4"
}
function get_netmask_num
{
local str=`cat $1 | grep "^[[:space:]]*[^#]"|grep net_mask_l |awk -F '=' '{print $2}'|tr -d '"'`
local i=4
local number=""
while [ $i -gt 0 ]
do
number=`echo $str|awk -F '.' '{print $'$i'}'`
if [ $number -eq 255 ];then
let "num+=8"
elif [ $number -eq 0 ];then
let "num+=0"
elif [ $number -eq 254 ];then
let "num+=7"
elif [ $number -eq 252 ];then
let "num+=6"
elif [ $number -eq 248 ];then
let "num+=5"
elif [ $number -eq 240 ];then
let "num+=4"
elif [ $number -eq 224 ];then
let "num+=3"
elif [ $number -eq 192 ];then
let "num+=2"
elif [ $number -eq 128 ];then
let "num+=1"
fi
let "i-=1"
done
# echo $num
}
#选择虚拟化实现机制ovs or sriov
function ask_virtualization_mechanism
{
local CUSTOM_CFG_FILE=$1
# echo ""
# echo -e ">>which virtualized mechanism would you like,ovs or sriov [default ovs]: \c"
# read parm
# case $parm in
# "ovs")
# set_config $CUSTOM_CFG_FILE "virtualization_mechanism" "ovs"
# ask_data_bond $CUSTOM_CFG_FILE
# echo
# ;;
# "sriov")
# set_config $CUSTOM_CFG_FILE "virtualization_mechanism" "sriov"
# ask_data_bond $CUSTOM_CFG_FILE
# echo
# ;;
# "")
# set_config $CUSTOM_CFG_FILE "virtualization_mechanism" "ovs"
ask_data_bond $CUSTOM_CFG_FILE
# echo
# ;;
# *)
# echo "Please input ovs or sriov"
# ask_virtualization_mechanism $CUSTOM_CFG_FILE
# ;;
# esac
}
#设置是否需要做数据面bond
function ask_data_bond
{
local CUSTOM_CFG_FILE=$1
eth=""
bond_eth[97]="XXXXXX"
num=0
phy=0
# echo ""
echo -e ">>Client machine data port use bonding ,yes or no[default no]: \c"
read parm
[[ ! -z `echo $parm |grep -iwE "y|yes"` ]] && parm=yes
[[ ! -z `echo $parm |grep -iwE "n|no"` ]] && parm=no
case $parm in
"yes")
set_config $CUSTOM_CFG_FILE "data_port_is_using_bonding" "yes"
ask_ovs_bond_port_name $CUSTOM_CFG_FILE
ask_sriov_bond_port_name $CUSTOM_CFG_FILE
echo
;;
"no")
set_config $CUSTOM_CFG_FILE "data_port_is_using_bonding" "no"
ask_data_config $CUSTOM_CFG_FILE
echo
;;
"")
set_config $CUSTOM_CFG_FILE "data_port_is_using_bonding" "no"
ask_data_config $CUSTOM_CFG_FILE
echo
;;
*)
echo "Please input yes or no"
ask_data_bond $CUSTOM_CFG_FILE
;;
esac
}
function bond_eth_check
{
local i=""
local mark=0
eth=$1
while true
do
#while [ ! -f "/etc/sysconfig/network-scripts/ifcfg-$eth" ]
#do
#echo -e ">>the network card which name is $eth is not exist ,please input a new one: \c"
#read eth
#done
#echo "OK"
for i in ${bond_eth[@]}
do
#echo "i $i"
if [ $i = $eth ];then
echo -e ">>The network card which name is $eth is Inused ,please input a new one: \c"
read eth
mark=0
break
fi
mark=1
done
if [ $mark -eq 1 ];then
mark=0
break
fi
done
}
#确定哪些网口需要ovs_bond处理
function ask_ovs_bond_port_name
{
local CUSTOM_CFG_FILE=$1
local i=1
ovs_first=""
ovs_second=""
echo ""
echo -e ">>Please input the number of the ovs_bond which you wan to make [default:1]: \c"
read bond_num
if [[ -z $bond_num ]]; then
bond_num=1
fi
expr $bond_num "+" 10 &> /dev/null
while [ $? -ne 0 ]
do
echo ""
echo -e ">>Please input an number[default:1]: \c"
read bond_num
if [[ -z $bond_num ]];then
bond_num=1
fi
expr $bond_num "+" 10 &> /dev/null
done
set_config $CUSTOM_CFG_FILE "ovs-port-bond_num" "$bond_num"
num=$bond_num
phy=$bond_num
while [ $i -le $bond_num ]
do
if [ $bond_num -eq 1 ];then
echo ""
echo "Data port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name with bond1 [default:eth0,eth1]: \c"
read parm1
if [[ -z $parm1 ]];then
parm1="eth0,eth1"
fi
ovs_first=`echo $parm1|awk -F , '{print $1}'`
bond_eth_check $ovs_first
ovs_first=$eth
bond_eth[i*2-1]=$ovs_first
ovs_second=`echo $parm1|awk -F , '{print $2}'`
bond_eth_check $ovs_second
ovs_second=$eth
parm1="$ovs_first,$ovs_second"
bond_ovs[i*2-1]=$parm1
bond_ovs[i*2]="$ovs_second,$ovs_first"
bond_eth[i*2]=$ovs_second
set_config $CUSTOM_CFG_FILE "ovs_port_uplink_port1" "$parm1"
while true; do
bond_mode="0"
echo "Please select bond mode:"
echo " 0 -- backup"
echo " 1 -- on"
echo " 2 -- lacp"
echo -e "input bond mode:\c"
read bond_mode
if ( [ "$bond_mode" = "0" ] || [ "$bond_mode" = "1" ] || [ "$bond_mode" = "2" ] ); then
break
fi
done
ovs_bond_mode[i]=$bond_mode
set_config $CUSTOM_CFG_FILE "ovs_port_bond_mode$i" "$bond_mode"
echo ""
echo -e ">>Set the number of mtu_mappings[default:1520]: \c"
read parm2
if [[ -z $parm2 ]];then
parm2=1520
fi
set_config $CUSTOM_CFG_FILE "ovs_mtu_mappings$i" "$parm2"
set_config $CUSTOM_CFG_FILE "ovs_phynet_name$i" "physnet$i"
set_config $CUSTOM_CFG_FILE "ovs_bridge_name$i" "br-bond$i"
set_config $CUSTOM_CFG_FILE "ovs_bond_name$i" "bond$i"
else
if [ $i -ge 4 ];then
echo "[ovs-port-bond$i]" >> $CUSTOM_CFG_FILE
fi
echo ""
echo "Data port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name with bond$i,the input can not be empty: \c"
read parm1
ovs_first=`echo $parm1|awk -F , '{print $1}'`
bond_eth_check $ovs_first
ovs_first=$eth
bond_eth[i*2-1]=$ovs_first
ovs_second=`echo $parm1|awk -F , '{print $2}'`
bond_eth_check $ovs_second
ovs_second=$eth
parm1="$ovs_first,$ovs_second"
bond_ovs[i*2-1]=$parm1
bond_ovs[i*2]="$ovs_second,$ovs_first"
bond_eth[i*2]=$ovs_second
set_config $CUSTOM_CFG_FILE "ovs_port_uplink_port$i" "$parm1"
while true; do
echo "Please select bond mode:"
echo " 0 -- backup"
echo " 1 -- on"
echo " 2 -- lacp"
echo -e "Input bond mode:\c"
read bond_mode
if ( [ "$bond_mode" = "0" ] || [ "$bond_mode" = "1" ] || [ "$bond_mode" = "2" ] ); then
break
fi
done
ovs_bond_mode[i]=$bond_mode
set_config $CUSTOM_CFG_FILE "ovs_port_bond_mode$i" "$bond_mode"
echo ""
echo -e ">>set the number of mtu_mappings: \c"
read parm2
set_config $CUSTOM_CFG_FILE "ovs_mtu_mappings$i" "$parm2"
set_config $CUSTOM_CFG_FILE "ovs_phynet_name$i" "physnet$i"
set_config $CUSTOM_CFG_FILE "ovs_bridge_name$i" "br-bond$i"
set_config $CUSTOM_CFG_FILE "ovs_bond_name$i" "bond$i"
fi
let "i+=1"
done
}
function sriov_check_with_ovs
{
local i=""
local j=1
for i in ${bond_ovs[@]}
do
let "j+=1"
if [ $i = $parm ];then
if [ ${ovs_bond_mode[j/2]} = $sriov_mode ];then
mark=1
flag=1
flag_num=`expr $j / 2`
break
else
echo "This bond has been made in ovs , but the bond_mode is not same ,please try again"
echo "Data port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name with bond,the input can not be empty: \c"
read parm
while true; do
echo "Please select bond mode:"
echo " 0 -- backup"
echo " 1 -- on"
echo " 2 -- lacp"
echo -e "Input bond mode:\c"
read mode
if ( [ "$mode" = "0" ] || [ "$mode" = "1" ] || [ "$mode" = "2" ] ); then
break
fi
done
sriov_mode=$mode
sriov_check_with_ovs
break
fi
fi
done
}
function sriov_check_bond
{
mark=0
local j=0
local n=0
parm=$1
sriov_mode=$2
sriov_check_with_ovs
if [ $mark -eq 1 ];then
mark=0
sriov_first=`echo $parm|awk -F , '{print $1}'`
sriov_second=`echo $parm|awk -F , '{print $2}'`
else
sriov_first=`echo $parm|awk -F , '{print $1}'`
sriov_second=`echo $parm|awk -F , '{print $2}'`
bond_eth_check $sriov_first
sriov_first=$eth
bond_eth[num*2-1]=$sriov_first
bond_eth_check $sriov_second
sriov_second=$eth
bond_eth[num*2]=$sriov_second
let "num+=1"
fi
}
#确定哪些网口需要sriov_bond处理
function ask_sriov_bond_port_name
{
flag=0
flag_num=0
local CUSTOM_CFG_FILE=$1
local i=1
sriov_first=""
sriov_second=""
sriov_mode=""
let "phy+=1"
let "num+=1"
echo ""
echo -e ">>Please input the number of the sriov_bond which you wan to make [default:1]: \c"
read bond_num
if [[ -z $bond_num ]] ;then
bond_num=1
fi
expr $bond_num "+" 10 &> /dev/null
while [ $? -ne 0 ]
do
echo ""
echo -e ">>Please input an number[default:1]: \c"
read bond_num
if [[ -z $bond_num ]];then
bond_num=1
fi
expr $bond_num "+" 10 &> /dev/null
done
set_config $CUSTOM_CFG_FILE "sriov-port-bond_num" "$bond_num"
while [ $i -le $bond_num ]
do
if [ $bond_num -eq 1 ];then
echo ""
echo "Data port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name with bond1 [default:eth0,eth1]: \c"
read parm1
if [[ -z $parm1 ]];then
parm1="eth0,eth1"
fi
while true; do
echo "Please select bond mode:"
echo " 0 -- backup"
echo " 1 -- on"
echo " 2 -- lacp"
echo -e "Input bond mode:\c"
read bond_mode
if ( [ "$bond_mode" = "0" ] || [ "$bond_mode" = "1" ] || [ "$bond_mode" = "2" ] ); then
break
fi
done
sriov_check_bond $parm1 $bond_mode
if [ $flag -eq 1 ];then
set_config $CUSTOM_CFG_FILE "sriov_phynet_name$i" "physnet$flag_num"
set_config $CUSTOM_CFG_FILE "sriov_bridge_name$i" "br-bond$flag_num"
set_config $CUSTOM_CFG_FILE "sriov_bond_name$i" "bond$flag_num"
flag=0
flag_num=0
else
set_config $CUSTOM_CFG_FILE "sriov_phynet_name$i" "physnet$phy"
set_config $CUSTOM_CFG_FILE "sriov_bridge_name$i" "br-bond$phy"
set_config $CUSTOM_CFG_FILE "sriov_bond_name$i" "bond$phy"
fi
set_config $CUSTOM_CFG_FILE "sriov_port_uplink_port$i" "$sriov_first,$sriov_second"
set_config $CUSTOM_CFG_FILE "sriov_port_bond_mode$i" "$sriov_mode"
echo ""
echo -e ">>Set the number of mtu_mappings[default:1520]: \c"
read parm2
if [[ -z $parm2 ]];then
parm2=1520
fi
set_config $CUSTOM_CFG_FILE "sriov_mtu_mappings1" "$parm2"
else
if [ $i -ge 4 ];then
echo "[sriov-port-bond$i]" >> $CUSTOM_CFG_FILE
fi
echo ""
echo "Data port using bonding need to set uplink nic name. More than one nic name,separated by commas."
echo -e ">>Enter client host bonding uplink nic name with bond$i,the input can not be empty: \c"
read parm1
while true; do
echo "Please select bond mode:"
echo " 0 -- backup"
echo " 1 -- on"
echo " 2 -- lacp"
echo -e "Input bond mode:\c"
read bond_mode
if ( [ "$bond_mode" = "0" ] || [ "$bond_mode" = "1" ] || [ "$bond_mode" = "2" ] ); then
break
fi
done
sriov_check_bond $parm1 $bond_mode
if [ $flag -eq 1 ];then
set_config $CUSTOM_CFG_FILE "sriov_phynet_name$i" "physnet$flag_num"
set_config $CUSTOM_CFG_FILE "sriov_bridge_name$i" "br-bond$flag_num"
set_config $CUSTOM_CFG_FILE "sriov_bond_name$i" "bond$flag_num"
flag=0
flag_num=0
else
set_config $CUSTOM_CFG_FILE "sriov_phynet_name$i" "physnet$phy"
set_config $CUSTOM_CFG_FILE "sriov_bridge_name$i" "br-bond$phy"
set_config $CUSTOM_CFG_FILE "sriov_bond_name$i" "bond$phy"
fi
set_config $CUSTOM_CFG_FILE "sriov_port_uplink_port$i" "$sriov_first,$sriov_second"
set_config $CUSTOM_CFG_FILE "sriov_port_bond_mode$i" "$sriov_mode"
echo ""
echo -e ">>Set the number of mtu_mappings: \c"
read parm2
set_config $CUSTOM_CFG_FILE "sriov_mtu_mappings$i" "$parm2"
fi
let "i+=1"
let "phy+=1"
done
}
#不做bond处理需要配置的物理口
function ask_data_config
{
local CUSTOM_CFG_FILE=$1
local phynic_port
local pci_net_phy
echo ""
echo -e ">>Please input bridge interface.The interface will be added to the associated bridge.It must be different from Private interface and Public interface. (default: er0): \c"
read parm1
if [[ -z $parm1 ]];then
phynic_port="er0"
else
phynic_port=$parm1
fi
set_config $CUSTOM_CFG_FILE "data_port_phynic" "$phynic_port"
}

View File

@ -0,0 +1,6 @@
说明:
1.在此目录中的文件,都将自动拷贝到安装系统后的目标机的/home/opencos_install/custom/目录
2.before.sh 文件是用来一键执行/home/opencos_install/custom/before下的所有的before_开头的shell脚本
3.after.sh 文件是用来一键执行/home/opencos_install/custom/after的所有的after_开头的shell脚本
4.before文件夹放安装opencos文件夹前执行的脚本after为安装文件夹后执行的脚本
5.各模块的交互脚本放在custom/interact目录下添加新脚本后须在custom目录interact.sh中添加调用代码。

View File

@ -0,0 +1,183 @@
#!/bin/bash
WORKDIR=/etc/pxe_install
source $WORKDIR/scripts/setup_func.sh
#source ./pxe_func.sh
source $WORKDIR/scripts/custom/interact.sh
#######################
#为pxe server设置ip
#######################
function set_svrip
{
local ENV_CFG=$1
# 解析配置文件获取dhcp服务守护的网卡名
get_config $ENV_CFG "ethname_l"
nic4dhcp=$config_answer
# 获取网卡信息
get_config $ENV_CFG "ip_addr_l"
ipaddr=$config_answer
get_config $ENV_CFG "net_mask_l"
netmask=$config_answer
pxelog "netmask is $netmask" "console"
# 把多余的网口地址给清理掉
for i in `ls /sys/class/net/`
do
is_link=`readlink /sys/class/net/$i | grep -c '/'`
if [[ $is_link -eq 0 ]]; then
continue
fi
if [ `ifconfig | grep -c $i:100` -eq 0 ]; then
continue
fi
if [ `ifconfig $i:100 | grep -c "$ipaddr"` -eq 0 ]; then
continue
fi
ifconfig $i:100 | grep -c "$ipaddr"
ifconfig $i:100 0
rm -rf /etc/sysconfig/network-scripts/ifcfg-"$i":100
done
# 为服务端配置ip地址重启后有效
[[ `ifconfig $nic4dhcp |grep flag |grep -w UP` == "" ]] && ifconfig $nic4dhcp up
ifconfig $nic4dhcp:100 $ipaddr netmask $netmask up
nicfile=/etc/sysconfig/network-scripts/ifcfg-"$nic4dhcp":100
touch $nicfile
echo "DEVICE=\"$nic4dhcp:100\"" > $nicfile
echo "BOOTPROTO=\"static\"" >> $nicfile
echo "ONBOOT=\"yes\"" >> $nicfile
echo "IPADDR=$ipaddr" >> $nicfile
echo "NETMASK=$netmask" >> $nicfile
}
#######################
#安装pxe组件
#######################
function install_pxe
{
local pxedir=$1
cd $pxedir
#/* 安装tftp 的RPM包 */
rpm -qi xinetd >/dev/null
[ $? -ne 0 ] && rpm -ivh ./xinetd-2.3.15-12.el7.x86_64.rpm
rpm -qi tftp-server >/dev/null
[ $? -ne 0 ] && rpm -ivh ./tftp-server-5.2-11.el7.x86_64.rpm
rpm -qi tftp >/dev/null
[ $? -ne 0 ] && rpm -ivh ./tftp-5.2-11.el7.x86_64.rpm
#/* 安装PXE包 */
rpm -qi ipxe-roms-qemu >/dev/null
[ $? -ne 0 ] && rpm -ivh ./ipxe-roms-qemu-20130517-5.gitc4bce43.el7.noarch.rpm
rpm -qi syslinux >/dev/null
[ $? -ne 0 ] && rpm -ivh ./syslinux-4.05-8.el7.x86_64.rpm
#/* 安装DHCP包 */
rpm -qi dhcp-common >/dev/null
[ $? -ne 0 ] && rpm -ivh ./dhcp-common-4.2.5-27.el7.x86_64.rpm
rpm -qi dhcp >/dev/null
[ $? -ne 0 ] && rpm -ivh ./dhcp-4.2.5-27.el7.x86_64.rpm
#/* 安装ntpdate包 */
rpm -qi ntpdate >/dev/null
[ $? -ne 0 ] && rpm -ivh ./ntpdate-4.2.6p5-18.el7.x86_64.rpm
# 配置tftp
mkdir -p /tftpboot/pxelinux.cfg/
# 拷贝当前目录下的tftp文件到 xinetd.d下面
cp -rf ./tftp /etc/xinetd.d/
cp -rf default /tftpboot/pxelinux.cfg/default
cp -rf ./dhcpd.conf /etc/dhcp
}
#######################
#定制pxe配置文件需要修改dhcpd.conf/default
#######################
function custom_pxecfg
{
pxelog "custom_pxecfg..." "console"
local ENV_CFG=$1
local DHCP_CFG=/etc/dhcp/dhcpd.conf
local DEFAULT_CFG=/tftpboot/pxelinux.cfg/default
get_config $ENV_CFG "ip_addr_l"
svrip=$config_answer
get_config $ENV_CFG "net_mask_l"
mask=$config_answer
subnet=`ipcalc -n "$svrip" "$mask" |awk -F'=' '{print $2}'`
get_config $ENV_CFG "client_ip_begin"
begin=$config_answer
get_config $ENV_CFG "client_ip_end"
end=$config_answer
#sed -i "s/nfs:.*:\//nfs:$svrip:\//g" $DEFAULT_CFG
#将default下的ks配置删除增加dhcp_ip的配置
sed -i "s/ks=.*pxe_kickstart.cfg/dhcp_ip=$svrip/g" $DEFAULT_CFG
sed -i "s/next-server.*/next-server $svrip;/g" $DHCP_CFG
sed -i "s/subnet.*netmask.*{/subnet $subnet netmask $mask {/g" $DHCP_CFG
sed -i "s/option routers.*;/option routers $svrip;/g" $DHCP_CFG
sed -i "s/option subnet-mask.*;/option subnet-mask $mask;/g" $DHCP_CFG
sed -i "s/range.*;/range $begin $end;/g" $DHCP_CFG
}
#######################
#启动pxe服务
#######################
function start_pxesvr
{
# 关闭防火墙
service iptables stop
#/* 启动NFS服务 */
service nfs restart
#/* 启动PXE服务 */
service xinetd restart
#/* 启动DHCP服务 */
if [ `service dhcpd status | grep -c running` == 0 ]; then
service dhcpd restart
pxelog "Inatall Environment Prepare Success! Have fun!" "console"
else
service dhcpd restart
pxelog "Warning............................" "console"
pxelog "Warning............................" "console"
pxelog "Warning: other DHCP is Running. Restart DHCP....." "console"
pxelog "Please Check Current Dhcp config. Sure Current Dhcp Can Auto Install ISO" "console"
pxelog "Warning............................" "console"
pxelog "Warning............................" "console"
fi
# 设置pxe相关服务为开机自启动 --added by xuyang
chkconfig --level 2345 nfs-server on
chkconfig --level 2345 xinetd on
chkconfig --level 2345 dhcpd on
chkconfig --level 2345 iptables off
}
#pxe从上层目录的usrdata拷贝第三方文件到系统
#拷贝到服务器的/home/install_share

View File

@ -0,0 +1,194 @@
#! /bin/bash
is_sbcx=no
TEMPLATE_IFCFG=/etc/sysconfig/network-scripts/template-ifcfg
#######################
#获取服务器类型
#######################
function get_board_type
{
is_sbcx=no
if [[ `dmidecode |grep "SBCJ"` != "" ]];then
is_sbcx=yes
fi
if [[ `dmidecode |grep "SBCR"` != "" ]];then
is_sbcx=yes
fi
return 0
}
#######################
#删除现有网口的配置文件
#######################
function rm_ifcfg_file
{
IFCFG=/etc/sysconfig/network-scripts/
for i in `ls /etc/sysconfig/network-scripts/ |grep ifcfg-`;
do
if [[ $i != "ifcfg-lo" ]];then
rm $IFCFG$i
fi
done
return 0
}
#######################
#生成网口配置文件模板
#######################
function create_tmp_ifcfg
{
if [ ! -e $TEMPLATE_IFCFG ] ; then
cat >>$TEMPLATE_IFCFG <<'EOF'
BOOTPROTO="static"
ONBOOT="yes"
EOF
fi
return 0
}
#######################
#网口固化实现
#######################
function eth_nicfix
{
local eth_name=$1
local eth_pci=$2
local udev_config_file="/etc/udev/rules.d/72-nicfix.rules"
#SBCJ和SBCR刀片修改其他服务器直接修改udev规则
#if [[ ${is_sbcx} = "yes" ]];then
# echo "sbcx"
#else
# echo "not sbcx"
#fi
[[ ! -e $udev_config_file ]] && touch $udev_config_file
if [[ -z `cat $udev_config_file | grep "$eth_pci"` ]];then
local rule="SUBSYSTEM==\"net\", ACTION==\"add\", KERNELS==\"${eth_pci}\", NAME:=\"${eth_name}\""
echo ${rule} >> $udev_config_file
else
sed -i "/$eth_pci/s/NAME:=\".*\"/NAME:=\"${eth_name}\"/" $udev_config_file
fi
}
#######################
#网口配置修改
#######################
function eth_config
{
local eth_name=$1
local eth_ip=$2
local eth_netmask=$3
local eth_gateway=$4
local eth_mode=$5
local IFCFG=/etc/sysconfig/network-scripts/ifcfg-$eth_name
create_tmp_ifcfg
if [ ! -e $IFCFG ]; then
cp -f $TEMPLATE_IFCFG $IFCFG
echo "nicfix: creat $IFCFG "
echo "DEVICE=\"$eth_name\"" >> $IFCFG
else
#如果该网口是bond成员口那么不需要配ip
if [[ `cat $IFCFG |grep "SLAVE=yes"` != "" ]]; then
eth_ip=""
eth_netmask=""
eth_gateway=""
eth_mode=""
fi
fi
sed -i '/HWADDR/d' $IFCFG
[[ ! -z $eth_ip ]] && echo "IPADDR=\"$eth_ip\"" >> $IFCFG
[[ ! -z $eth_netmask ]] && echo "NETMASK=\"$eth_netmask\"" >> $IFCFG
[[ ! -z $eth_gateway ]] && echo "GATEWAY=\"$eth_gateway\"" >> $IFCFG
[[ ! -z $eth_mode ]] && echo "BONDING_OPTS=\"miimon=100 mode=$eth_mode\"" >> $IFCFG
}
#######################
#bond口配置修改
#######################
function bond_config
{
local bond_name=$1
local bond_ip=$2
local bond_netmask=$3
local bond_gateway=$4
local bond_mode=$5
local bond_slave1=$6
local bond_slave2=$7
#生成ifcfg-$bond_name
eth_config "$bond_name" "$bond_ip" "$bond_netmask" "$bond_gateway" "$bond_mode"
#修改/etc/modprobe.d/bonding.conf
local BOND_CFG=/etc/modprobe.d/bonding.conf
[ ! -e ${BOND_CFG} ] && touch ${BOND_CFG}
echo "alias ${bond_name} bonding" >>${BOND_CFG}
echo "options ${bond_name} miimon=100 mode=${bond_mode}" >>${BOND_CFG}
#修改各bond成员口的配置文件
local bond_port="$bond_slave1 $bond_slave2"
for i in ${bond_port};
do
local IFCFG=/etc/sysconfig/network-scripts/ifcfg-$i
if [ ! -e $IFCFG ]; then
eth_config "$i" "" "" "" ""
else
#bond成员口不需要配ip
sed -i '/IPADDR/d' $IFCFG
sed -i '/NETMASK/d' $IFCFG
sed -i '/GATEWAY/d' $IFCFG
fi
if [[ `cat $IFCFG |grep "MASTER"` = "" ]]; then
echo "MASTER=$bond_name" >> $IFCFG
else
sed -i "s/MASTER=.*/MASTER=$bond_name/" $IFCFG
fi
if [[ `cat $IFCFG |grep "SLAVE"` = "" ]]; then
echo "SLAVE=yes" >> $IFCFG
else
sed -i "s/SLAVE=.*/SLAVE=yes/" $IFCFG
fi
done
}
function vlan_config
{
local eth_name=$1
local vlan_id=$2
local eth_ip=$3
local eth_netmask=$4
local eth_gateway=$5
local vlan_eth_name="$eth_name.$vlan_id"
ip link add link $eth_name name $vlan_eth_name type vlan id $vlan_id
#生成ifcfg-$vlan_eth_name
eth_config "$vlan_eth_name" "$eth_ip" "$eth_netmask" "$eth_gateway" ""
echo "VLAN=yes" >>/etc/sysconfig/network-scripts/ifcfg-$vlan_eth_name
}
###################start#################
#获取服务器类型
#get_board_type
#删除现有网口的配置文件
rm_ifcfg_file
#停止我们自己的网口固化服务
systemctl disable nicfix.service
systemctl stop nicfix.service

View File

@ -0,0 +1,261 @@
#!/bin/bash
###############################################################################################
# 功能获取os安装进度的函数定义
###############################################################################################
function find_string_in_file
{
local file=$1
local string=$2
exist=yes
local result=`cat ${file} |grep -a "${string}"`
[[ ${result} == "" ]] && exist=no
}
function print_progress
{
local OS_TABLE=$1
local MACADDR=$2
local descript
descript=`cat ${OS_TABLE} | grep -wi "${MACADDR}" |awk -F' ' '{print $2" "$3}'`
pxelog "${descript}" "console"
}
function modify_os_table
{
local OS_TABLE=$1
local MACADDR=$2
local rate_value=$3
local rate_descript=$4
local tmp_rate=`cat $OS_TABLE | grep -wi "$MACADDR" |awk -F' ' '{print $2}'`
[[ $rate_value == $tmp_rate ]] && return 0
local linuxinstall_dir=`cat $OS_TABLE | grep -wi "$MACADDR" |awk -F' ' '{print $4}'`
sed -i "s%${MACADDR}.*%${MACADDR} ${rate_value} ${rate_descript} ${linuxinstall_dir}%g" ${OS_TABLE}
}
#设置完成
function set_done
{
local INSTALL_LOG=$1
local OS_TABLE=$2
local MACADDR=$3
modify_os_table ${OS_TABLE} ${MACADDR} "100" "done_install"
pxelog "${MACADDR} install complete, will clean files and ${INSTALL_LOG}!"
print_progress ${OS_TABLE} ${MACADDR}
clean_os_files ${MACADDR} ${OS_TABLE}
echo > ${INSTALL_LOG}
}
#此函数就是从日志文件中找anaconda程序各个阶段的关键字来确认安装进度每个阶段对应的安装进度是固定的
#从最后的阶段往前开始搜索,除了给出进度值,还需要更新服务器上的一个目标机安装统计表
#出现anaconda: Thread Done: AnaConfigurationThread----100% done_install
#出现anaconda: Running Thread: AnaConfigurationThread----62%-100% post_config
#出现anaconda: Running Thread: AnaInstallThread----2%-62% package_install期间需要再细化
#出现anaconda: Running Thread: AnaStorageThread----1% storage_config
#其余0% plan_install
#$1: 目标机安装日志文件
#$2: 目标机安装统计表
#$3: 目标机mac地址
function get_progress_rh70_base
{
local INSTALL_LOG=$1
local OS_TABLE=$2
local MACADDR=$3
local descript
local rate_value
#查看日志搜索anaconda: Thread Done: AnaConfigurationThread,搜到了表示安装完成进度是100%
descript="anaconda: Thread Done: AnaConfigurationThread"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
set_done $INSTALL_LOG $OS_TABLE $MACADDR
return 0
fi
#查看日志搜索anaconda: Running Thread: AnaConfigurationThread搜到了表示在执行post阶段的配置进度是62%-100%,这里又分好几个阶段
descript="anaconda: Running Thread: AnaConfigurationThread"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
#查看日志搜索yum.*Installed的个数总共28个期间百分比是79-96%
number=`cat ${INSTALL_LOG} |grep "yum.*Installed" | wc -l`
if [ ${number} -gt 0 ]; then
((rate_value=${number}*17/28+79))
[[ $rate_value -gt 99 ]] && rate_value=99
modify_os_table ${OS_TABLE} ${MACADDR} "${rate_value}" "post_config"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索anaconda: Running post-installation scripts,搜到了表示已经执行了66%
descript="anaconda: Running post-installation scripts"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
modify_os_table ${OS_TABLE} ${MACADDR} "66" "post_config"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
modify_os_table ${OS_TABLE} ${MACADDR} "62" "post_config"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索anaconda: Running Thread: AnaInstallThread搜到了表示在执行package的安装2%-62%,这里又分好几个阶段
descript="anaconda: Running Thread: AnaInstallThread"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
#查看日志搜索packaging: transaction complete搜到了表示已经执行完61%
descript="packaging: transaction complete"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
modify_os_table ${OS_TABLE} ${MACADDR} "61" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索packaging: Installed products updated搜到了表示已经执行完54%
descript="packaging: Installed products updated"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
modify_os_table ${OS_TABLE} ${MACADDR} "54" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索packaging: Performing post-installation setup tasks搜到了表示已经执行完43%
descript="packaging: Performing post-installation setup tasks"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
modify_os_table ${OS_TABLE} ${MACADDR} "43" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索packaging: Preparing transaction from installation source搜到了表示在5%-43%之间,需要根据安装的包数再细化
descript="packaging: Preparing transaction from installation source"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
descript="packaging: Installing"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
#根据安装包数计算进度
#获取到日志中安装的最后一条记录packaging: Installing **** (**/***)
descript=`cat ${INSTALL_LOG} |grep "packaging: Installing" | tail -n 1`
#截取出安装的包数和总包数**/***
descript=${descript%\)*}
descript=${descript##*\(}
local total_pachages=${descript#*/}
local installed_packages=${descript%/*}
pxelog "total_pachages=$total_pachages installed_packages=$installed_packages"
((rate_value=${installed_packages}*38/${total_pachages}+5))
modify_os_table ${OS_TABLE} ${MACADDR} "${rate_value}" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
modify_os_table ${OS_TABLE} ${MACADDR} "5" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
modify_os_table ${OS_TABLE} ${MACADDR} "2" "package_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#查看日志搜索anaconda: Running Thread: AnaStorageThread搜到了表示在执行存储设备的配置进度是1%
descript="anaconda: Running Thread: AnaStorageThread"
find_string_in_file ${INSTALL_LOG} "${descript}"
if [ ${exist} == yes ]; then
modify_os_table ${OS_TABLE} ${MACADDR} "1" "storage_config"
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
modify_os_table ${OS_TABLE} ${MACADDR} "0" "plan_install"
print_progress ${OS_TABLE} ${MACADDR}
return 0
}
function get_progress_rh65_base
{
local INSTALL_LOG=$1
local OS_TABLE=$2
local MACADDR=$3
local tmp_process=""
local tmp_rate=""
local array_process=("complete" "dopostaction" "postscripts" "methodcomplete" "copylogs" "setfilecon"
"writeksconfig" "reipl" "instbootloader" "firstboot" "writeconfig" "postinstallconfig"
"installpackages" "preinstallconfig" "install" "postselection" "basepkgsel" "reposetup"
"bootloadersetup" "enablefilesystems" "storagedone" "autopartitionexecute" "setuptime")
local array_rate=("100" "95" "90" "85" "80" "75"\
"70" "65" "60" "55" "50" "45"\
"40" "35" "30" "25" "20" "15"\
"10" "7" "3" "2" "1")
local array_process_num=${#array_process[@]}
local array_rate_num=${#array_rate[@]}
[[ $array_process_num != $array_rate_num ]] && { pxelog "array_process_num != array_rate_num"; return 1; }
for (( i=0; i<$array_process_num; i++ ))
do
tmp_process=${array_process[$i]}
tmp_rate=${array_rate[$i]}
#redhat6.5日志的特点是一个阶段开始的标志moving (1) to step *****阶段结束的标志leaving (1) step *****这里用开始的标志里的“to step *****”作为查询关键字
if [[ `cat $INSTALL_LOG | grep -w "to step $tmp_process"` != "" ]]; then
if [[ $tmp_rate == 100 ]]; then
set_done $INSTALL_LOG $OS_TABLE $MACADDR
else
modify_os_table ${OS_TABLE} ${MACADDR} "$tmp_rate" "$tmp_process"
print_progress ${OS_TABLE} ${MACADDR}
fi
break
fi
done
if [[ $i == $array_process_num ]]; then
modify_os_table ${OS_TABLE} ${MACADDR} "0" "plan_install"
print_progress ${OS_TABLE} ${MACADDR}
fi
}
function get_progress
{
local INSTALL_LOG=$1
local OS_TABLE=$2
local MACADDR=$3
local descript
local keywords="to step setuptime"
#日志不存在的情况下到目标机安装统计表上面去查一下相应的安装情况如果不是0%也不是100%,那么报错
if [ ! -f ${INSTALL_LOG} ]; then
descript=`cat ${OS_TABLE} | grep -wi "${MACADDR}" |awk -F' ' '{print $2}'`
if [[ ${descript} != "0" && ${descript} != "100" ]];then
modify_os_table ${OS_TABLE} ${MACADDR} "0" "error"
pxelog "log file ${INSTALL_LOG} not exist,can not get progress!"
fi
print_progress ${OS_TABLE} ${MACADDR}
return 0
fi
#到日志中查找关键字to step setuptime如果找到了则按redhat6.5的规则定进度否则按redhat7.0的方式
if [[ `cat $INSTALL_LOG |grep "$keywords"` != "" ]]; then
get_progress_rh65_base $@; return $?
else
get_progress_rh70_base $@; return $?
fi
}

View File

@ -0,0 +1,978 @@
#! /bin/bash
###############################################################################################
# 功能:安装目标机配置的一些函数定义
###############################################################################################
# 定制root用户口令
function custom_ks_rootpwd
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_rootpwd!"
get_config $CFG_FILE "root_pwd"
rootpwd=$config_answer
sed -i "s/rootpw.*$/rootpw $rootpwd/g" $KS_FILE
pxelog "started custom_ks_rootpwd!\n"
}
function custom_swap_size
{
local CFG_FILE=$1
local swap_from_json=$2
get_config $CFG_FILE "memory_size"
memsize=$config_answer
[[ -z $memsize || 0 -eq ${memsize} ]] && { pxelog "[error]memory_size is invalid: $memsize!\n" "console"; return 1; }
if [[ $memsize -le 4 ]];then
swapsize=4000
elif [[ $memsize -le 16 ]];then
swapsize=8000
elif [[ $memsize -le 64 ]];then
swapsize=32000
elif [[ $memsize -gt 64 ]];then
swapsize=64000
else
swapsize=4000
fi
pxelog "swap size refer to memory_size: $swapsize M, and swap size from json: $swap_from_json M "
return 0
}
# 定制ks中的vg
# 修改ks中根盘盘符以及格式化磁盘的列表
# 支持多磁盘但是要指定根盘比如sda,sdb,sdc其中sda是根盘。sda包括boot区、cinder、root卷、机动的600M(用于biosboot、vg_sys卷组信息、根盘剩余空间grow方式分区最小要500M)、剩余空间。
# part: boot区400M、biosboot区1M、pv.01(大小是root卷+4M)、pv.02cinder大小、pv.03根盘剩余的空间、pv.04sdb、pv.05sdc....依次类推
# vg: vg_sys(pv.01)、cinder-volumes(pv.02)、vg_data(pv.03pv.04pv.05.....)_
# 下面按上面vg的顺序介绍上面各个逻辑卷的分配
# root逻辑卷vg_sys组无默认值一定要传入一个非0和非空的值daisy判断这个分区的大小至少50G
# cinder卷组名字cinder-volumes组默认为0如果指定则按实际大小分配属于pv.02分区cindervolumes组
# swap逻辑卷vg_data组无默认值一定要有传值且不能为0daisy会根据memory大小计算
# db逻辑卷vg_data组默认为0如果指定则按实际大小分配如果-1将vg_data剩余的空间都分配给db
# mongodb逻辑卷vg_data组默认为0如果指定则按实际大小分配如果-1将vg_data剩余的空间都分配给mongodb
# nova逻辑卷vg_data组默认为0如果指定则按实际大小分配如果-1将vg_data剩余的空间都分配给nova
# glance逻辑卷vg_data组默认为0如果指定则按实际大小分配如果-1将vg_data剩余的空间都分配给nova
# provider逻辑卷vg_data组默认为0如果指定则按实际大小分配如果-1将vg_data剩余的空间都分配给nova这个卷有个特殊的是安装的时候不指定挂载路径所以需要在post阶段创建逻辑卷
function custom_ks_vg_tfg
{
local CFG_FILE=$1
local KS_FILE=$2
local free_storage
local pv_01=4
local pv_no=0
local free_lv_name=""
local vg_data_part_list=""
local boot_size=400
#机动的600M目前使用的地方是biosboot 1M系统会划出1Mvg_sys除了root卷大小还需要多出4M要不然创建root卷失败另外根盘剩余空间用grow方式创建一个分区的时候最少要500M
local flexible_size=600
local vg_data_free=1024
pxelog "starting custom_ks_vg_tfg!"
#获取根盘盘符
get_config $CFG_FILE "root_disk"
root_disk=$config_answer
#修改ks文件中根盘盘符
sed -i "s/bootloader --location=mbr --boot-drive=sda --driveorder=sda/bootloader --location=mbr --boot-drive=${root_disk} --driveorder=${root_disk}/g" $KS_FILE
sed -i "s/part \/boot --fstype ext3 --size=400 --ondisk=sda/part \/boot --fstype ext3 --size=400 --ondisk=${root_disk}/g" $KS_FILE
sed -i "s/part biosboot --fstype=biosboot --size=1 --ondisk=sda/part biosboot --fstype=biosboot --size=1 --ondisk=${root_disk}/g" $KS_FILE
#获取盘符列表
get_config $CFG_FILE "disk_list"
disk_list=$config_answer
#修改ks文件中盘符列表
sed -i "s/--drives=sda/--drives=${disk_list}/g" $KS_FILE
sed -i "s/disknamelist=sda/disknamelist=${disk_list}/g" $KS_FILE
#获取总的硬盘大小所有扫到的盘总和单位是M
get_config $CFG_FILE "storage_size"
storage_size=$config_answer
[[ -z ${storage_size} || 0 = ${storage_size} ]] && { pxelog "[error]storage_size is invalid: ${storage_size} M!\n" "console"; return 1; }
free_storage=${storage_size}
pxelog "storage_size=${storage_size} M, free_storage=$free_storage M"
#boot分区固定写死了400M另外600M作为冗余
((free_storage=${free_storage}-${boot_size}-${flexible_size}))
pxelog "boot_size=${boot_size} M, flexible_size=${flexible_size} M, free_storage=$free_storage M"
#获取root大小创建在根盘上无默认值一定要传入一个非0和非空的值daisy判断这个分区的大小至少50G
get_config $CFG_FILE "root_lv_size"
root_lv_size=$config_answer
#如果没有配置或者配置为0则返回失败
[[ -z ${root_lv_size} || 0 = ${root_lv_size} ]] && { pxelog "[error]root_lv_size is invalid: ${root_lv_size} M!\n" "console"; return 1; }
sed -i '/^logvol \/ --fstype ext4/d' $KS_FILE
[ $root_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for root size($root_lv_size M)!\n" "console"; return 1; }
#root大小小于50G就告警
[ $root_lv_size -lt 51200 ] && { pxelog "[error]root size is $root_lv_size M, less than 50G, not enough for system working!\n" "console"; return 1; }
sed -i "/\#lv_root/a\logvol \/ --fstype ext4 --vgname=vg_sys --size=$root_lv_size --name=lv_root" $KS_FILE
((pv_01=$root_lv_size+$pv_01))
((free_storage=$free_storage-$root_lv_size))
pxelog "root_lv_size=${root_lv_size} M, free_storage=$free_storage M, pv_01=$pv_01 M"
#获取swap分区的大小无默认值一定要有传值且不能为0daisy会根据memory大小计算
get_config $CFG_FILE "swap_lv_size"
swap_lv_size=$config_answer
custom_swap_size $CFG_FILE $swap_lv_size || return 1
[[ -z ${swap_lv_size} || 0 = ${swap_lv_size} ]] && { pxelog "[error]swap_lv_size is invalid: ${swap_lv_size} M!\n" "console"; return 1; }
[ $swap_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for swap size($swap_lv_size M)!\n" "console"; return 1; }
sed -i "s/logvol swap.*/logvol swap --fstype swap --vgname=vg_data --size=$swap_lv_size --name=lv_swap/" $KS_FILE
((free_storage=$free_storage-$swap_lv_size))
pxelog "swap_lv_size=${swap_lv_size} M, free_storage=$free_storage M"
#获取db的大小默认为0如果指定则按实际大小分配如果为-1则暂时先设置为-1最后再根据剩余空间修改
get_config $CFG_FILE "db_lv_size"
db_lv_size=$config_answer
if [[ ${db_lv_size} == "-1" ]];then
[[ ${free_lv_name} != "" ]] && { pxelog "[error]${free_lv_name} is already -1, db_lv_size can not be set -1!\n" "console"; return 1; }
free_lv_name="db"
((free_storage=$free_storage-1))
fi
if [[ ! -z $db_lv_size && 0 -ne $db_lv_size ]]; then
sed -i '/^logvol \/var\/lib\/mysql/d' $KS_FILE
[ $db_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for db size($db_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_db/a\logvol \/var\/lib\/mysql --fstype ext4 --vgname=vg_data --size=$db_lv_size --name=lv_db" $KS_FILE
((free_storage=$free_storage-$db_lv_size))
fi
pxelog "db_lv_size=${db_lv_size} M, free_storage=$free_storage M"
#获取mongodb的大小默认为0如果指定则按实际大小分配如果为-1则暂时先设置为-1最后再根据剩余空间修改
get_config $CFG_FILE "mongodb_lv_size"
mongodb_lv_size=$config_answer
if [[ ${mongodb_lv_size} == "-1" ]];then
[[ ${free_lv_name} != "" ]] && { pxelog "[error]${free_lv_name} is already -1, mongodb_lv_size can not be set -1!\n" "console"; return 1; }
free_lv_name="mongodb"
((free_storage=$free_storage-1))
fi
if [[ ! -z $mongodb_lv_size && 0 -ne $mongodb_lv_size ]]; then
sed -i '/^logvol \/var\/lib\/mongodb/d' $KS_FILE
[ $mongodb_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for mongodb size($mongodb_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_mongodb/a\logvol \/var\/lib\/mongodb --fstype ext4 --vgname=vg_data --size=$mongodb_lv_size --name=lv_mongodb" $KS_FILE
((free_storage=$free_storage-$mongodb_lv_size))
fi
pxelog "mongodb_lv_size=${mongodb_lv_size} M, free_storage=$free_storage M"
#获取nova大小默认为0如果指定则按实际大小分配如果为-1则暂时先设置为-1最后再根据剩余空间修改
get_config $CFG_FILE "nova_lv_size"
nova_lv_size=$config_answer
if [[ ${nova_lv_size} == "-1" ]];then
[[ ${free_lv_name} != "" ]] && { pxelog "[error]${free_lv_name} is already -1, nova_lv_size can not be set -1!\n" "console"; return 1; }
free_lv_name="nova"
((free_storage=$free_storage-1))
fi
if [[ ! -z $nova_lv_size && 0 -ne $nova_lv_size ]]; then
sed -i '/^logvol \/var\/lib\/nova/d' $KS_FILE
[ $nova_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for nova size($nova_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_nova/a\logvol \/var\/lib\/nova --fstype ext4 --vgname=vg_data --size=$nova_lv_size --name=lv_nova" $KS_FILE
((free_storage=$free_storage-$nova_lv_size))
fi
pxelog "nova_lv_size=${nova_lv_size} M, free_storage=$free_storage M"
#获取glance大小默认为0如果指定则按实际大小分配如果为-1则暂时先设置为-1最后再根据剩余空间修改
get_config $CFG_FILE "glance_lv_size"
glance_lv_size=$config_answer
if [[ ${glance_lv_size} == "-1" ]];then
[[ ${free_lv_name} != "" ]] && { pxelog "[error]${free_lv_name} is already -1, glance_lv_size can not be set -1!\n" "console"; return 1; }
free_lv_name="glance"
((free_storage=$free_storage-1))
fi
if [[ ! -z $glance_lv_size && 0 -ne $glance_lv_size ]]; then
sed -i '/^logvol \/var\/lib\/glance/d' $KS_FILE
get_config $CFG_FILE "mount_glance"
mount_glance=$config_answer
#如果mount_glance为yes表示安装后自动挂载到/var/lig/glance创建逻辑卷用anaconda的logvol否则安装只创建卷不挂载这个操作在post阶段执行
if [[ $mount_glance != "yes" ]]; then
[ $glance_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for glance size($glance_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_glance_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_glance_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_glance_nomount/a\e2label \/dev\/mapper\/vg_data-lv_glance" $KS_FILE
sed -i "/\#lv_glance_nomount/a\mke2fs -t ext4 \/dev\/mapper\/vg_data-lv_glance" $KS_FILE
sed -i "/\#lv_glance_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_glance_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_glance_nomount/a\echo \"lvcreate -n lv_glance -L ${glance_lv_size}M -y vg_data\" >> /home/os_install/usrdata/pxe_install.log" $KS_FILE
sed -i "/\#lv_glance_nomount/a\lvcreate -n lv_glance -L ${glance_lv_size}M -y vg_data" $KS_FILE
((free_storage=$free_storage-$glance_lv_size))
else
[ $glance_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for glance size($glance_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_glance_mount/a\logvol \/var\/lib\/glance --fstype ext4 --vgname=vg_data --size=$glance_lv_size --name=lv_glance" $KS_FILE
((free_storage=$free_storage-$glance_lv_size))
fi
fi
pxelog "glance_lv_size=${glance_lv_size} M, free_storage=$free_storage M"
#获取provider大小默认为0如果指定则按实际大小分配如果为-1则暂时先设置为-1最后再根据剩余空间修改
get_config $CFG_FILE "provider_lv_size"
provider_lv_size=$config_answer
if [[ ${provider_lv_size} == "-1" ]];then
[[ ${free_lv_name} != "" ]] && { pxelog "[error]${free_lv_name} is already -1, provider_lv_size can not be set -1!\n" "console"; return 1; }
free_lv_name="provider"
((free_storage=$free_storage-1))
fi
if [[ ! -z $provider_lv_size && 0 -ne $provider_lv_size ]]; then
#安装只创建卷不挂载这个操作在post阶段执行
[ $provider_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for provider size($provider_lv_size M)!\n" "console"; return 1; }
sed -i "/\#lv_provider_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_provider_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_provider_nomount/a\e2label \/dev\/mapper\/vg_data-lv_provider" $KS_FILE
sed -i "/\#lv_provider_nomount/a\mke2fs -t ext4 \/dev\/mapper\/vg_data-lv_provider" $KS_FILE
sed -i "/\#lv_provider_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_provider_nomount/a\udevadm settle --timeout=300" $KS_FILE
sed -i "/\#lv_provider_nomount/a\echo \"lvcreate -n lv_provider -L ${provider_lv_size}M -y vg_data\" >> /home/os_install/usrdata/pxe_install.log" $KS_FILE
sed -i "/\#lv_provider_nomount/a\lvcreate -n lv_provider -L ${provider_lv_size}M -y vg_data" $KS_FILE
((free_storage=$free_storage-$provider_lv_size))
fi
pxelog "provider_lv_size=${provider_lv_size} M, free_storage=$free_storage M"
#设置pv.01包括root_lv_size、swap_lv_size的冗余空间
sed -i "/\#end_part/i\part pv.01 --size=$pv_01 --ondisk=${root_disk}" $KS_FILE
pxelog "vg_sys_size equal to $pv_01 M"
pv_no=1
#获取cinder分区的大小默认为0如果指定则按实际大小分配
get_config $CFG_FILE "cinder_vg_size"
cinder_vg_size=$config_answer
if [[ ! -z $cinder_vg_size && 0 -ne $cinder_vg_size ]]; then
#创建物理卷
((pv_no=${pv_no}+1))
[ $cinder_vg_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for cinder size($cinder_vg_size M)!\n" "console"; return 1; }
sed -i "/\#end_part/i\part pv.0${pv_no} --size=$cinder_vg_size --ondisk=${root_disk}" $KS_FILE
sed -i "s/volgroup cindervolumes pv.02 --pesize=4096/volgroup cindervolumes pv.0${pv_no} --pesize=4096/g" $KS_FILE
((free_storage=$free_storage-$cinder_vg_size))
else
#删除pv.2物理卷以及cinder vg
sed -i "/cindervolumes/d" $KS_FILE
fi
pxelog "cinder_vg_size=${cinder_vg_size} M, free_storage=$free_storage M"
#获取docker分区的大小默认为0如果指定则按实际大小分配
get_config $CFG_FILE "docker_vg_size"
docker_vg_size=$config_answer
if [[ ! -z $docker_vg_size && 0 -ne $docker_vg_size ]]; then
#创建物理卷
((pv_no=${pv_no}+1))
[ $docker_vg_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for docker size($docker_vg_size M)!\n" "console"; return 1; }
sed -i "/\#end_part/i\part pv.0${pv_no} --size=$docker_vg_size --ondisk=${root_disk}" $KS_FILE
sed -i "s/volgroup vg_docker pv.03 --pesize=4096/volgroup vg_docker pv.0${pv_no} --pesize=4096/g" $KS_FILE
((free_storage=$free_storage-$docker_vg_size))
else
#删除docker vg
sed -i "/vg_docker/d" $KS_FILE
fi
pxelog "docker_vg_size=${docker_vg_size} M, free_storage=$free_storage M"
#设置根盘剩余空间的分区
((pv_no=pv_no+1))
sed -i "/\#end_part/i\part pv.0${pv_no} --grow --ondisk=${root_disk}" $KS_FILE
vg_data_part_list="${vg_data_part_list}"" ""pv.0""${pv_no}"
pxelog "vg_data_part_list=${vg_data_part_list}"
#对其他的盘,每个盘都设置一个分区
disk_list_array=`echo ${disk_list} | sed "s/,/ /g"`
pxelog "disk_list_array=${disk_list_array}"
for i in ${disk_list_array};
do
if [[ $i != ${root_disk} ]];then
((pv_no=pv_no+1))
sed -i "/\#end_part/i\part pv.0${pv_no} --grow --ondisk=${i}" $KS_FILE
vg_data_part_list="${vg_data_part_list}"" ""pv.0""${pv_no}"
pxelog "vg_data_part_list=${vg_data_part_list}"
fi
done
#设置vg_data组
sed -i "s/volgroup vg_data.*/volgroup vg_data ${vg_data_part_list} --pesize=4096/g" $KS_FILE
((vg_data_size=${storage_size}-${boot_size}-${flexible_size}-${cinder_vg_size}-${pv_01}))
pxelog "vg_data_size About equal to ${vg_data_size} M"
#修改ks文件中size=-1的地方大小改成free_storage-vg_data_free(1G)
if [[ ${free_lv_name} != "" ]]; then
if [[ ${free_storage} -gt ${vg_data_free} ]]; then
((grow_size=${free_storage}-${vg_data_free}))
else
pxelog "[error]free_storage=${free_storage} M is less than to ${vg_data_free} M, insufficient for ${free_lv_name} lv" "console"
return 1
fi
sed -i "s/--size=-1/--size=${grow_size}/g" $KS_FILE
sed -i "s/-1M/${grow_size}M/g" $KS_FILE
pxelog "${free_lv_name} lv size is set to ${grow_size} M"
fi
pxelog "started custom_ks_vg_tfg!\n"
return 0
}
# 定制ks中的vg
# 修改ks中根盘盘符以及格式化磁盘的列表
# 只支持安装系统到根盘
# part: boot区400M、biosboot区1M、pv.01(大小是root卷+swap+8M)
# vg: vg_sys(pv.01)
# root逻辑卷vg_sys组无默认值一定要传入一个非0和非空的值daisy判断这个分区的大小至少50G
# swap逻辑卷vg_sys组无默认值一定要有传值且不能为0daisy会根据memory大小计算
function custom_ks_vg_else
{
local CFG_FILE=$1
local KS_FILE=$2
local free_storage
local pv_01=8
local pv_no=0
local free_lv_name=""
local vg_data_part_list=""
local boot_size=400
#机动的600M目前使用的地方是biosboot 1M系统会划出1Mvg_sys除了root卷大小还需要多出4M要不然创建root卷失败
local flexible_size=600
local vg_data_free=1024
pxelog "starting custom_ks_vg_else!"
#获取根盘盘符
get_config $CFG_FILE "root_disk"
root_disk=$config_answer
#修改ks文件中根盘盘符
sed -i "s/bootloader --location=mbr --boot-drive=sda --driveorder=sda/bootloader --location=mbr --driveorder=${root_disk}/g" $KS_FILE
sed -i "s/part \/boot --fstype ext3 --size=400 --ondisk=sda/part \/boot --fstype ext3 --size=400 --ondisk=${root_disk}/g" $KS_FILE
sed -i "s/part biosboot --fstype=biosboot --size=1 --ondisk=sda/part biosboot --fstype=biosboot --size=1 --ondisk=${root_disk}/g" $KS_FILE
#获取盘符列表
get_config $CFG_FILE "disk_list"
disk_list=$config_answer
#修改ks文件中盘符列表
sed -i "s/--drives=sda/--drives=${disk_list}/g" $KS_FILE
sed -i "s/disknamelist=sda/disknamelist=${disk_list}/g" $KS_FILE
#获取总的硬盘大小所有扫到的盘总和单位是M
get_config $CFG_FILE "storage_size"
storage_size=$config_answer
[[ -z ${storage_size} || 0 = ${storage_size} ]] && { pxelog "[error]storage_size is invalid: ${storage_size} M!\n" "console"; return 1; }
free_storage=${storage_size}
pxelog "storage_size=${storage_size} M, free_storage=$free_storage M"
#boot分区固定写死了400M另外600M作为冗余
((free_storage=${free_storage}-${boot_size}-${flexible_size}))
pxelog "boot_size=${boot_size} M, flexible_size=${flexible_size} M, free_storage=$free_storage M"
#获取root大小创建在根盘上无默认值一定要传入一个非0和非空的值daisy判断这个分区的大小至少50G
get_config $CFG_FILE "root_lv_size"
root_lv_size=$config_answer
#如果没有配置或者配置为0则返回失败
[[ -z ${root_lv_size} || 0 = ${root_lv_size} ]] && { pxelog "[error]root_lv_size is invalid: ${root_lv_size} M!\n" "console"; return 1; }
sed -i '/^logvol \/ --fstype ext4/d' $KS_FILE
[ $root_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for root size($root_lv_size M)!\n" "console"; return 1; }
#root大小小于50G就告警
[ $root_lv_size -lt 51200 ] && { pxelog "[error]root size is $root_lv_size M, less than 50G, not enough for system working!\n" "console"; return 1; }
sed -i "/\#lv_root/a\logvol \/ --fstype ext4 --vgname=vg_sys --size=$root_lv_size --name=lv_root" $KS_FILE
((pv_01=$root_lv_size+$pv_01))
((free_storage=$free_storage-$root_lv_size))
pxelog "root_lv_size=${root_lv_size} M, free_storage=$free_storage M, pv_01=$pv_01 M"
#获取swap分区的大小无默认值一定要有传值且不能为0daisy会根据memory大小计算
get_config $CFG_FILE "swap_lv_size"
swap_lv_size=$config_answer
custom_swap_size $CFG_FILE $swap_lv_size || return 1
[[ -z ${swap_lv_size} || 0 = ${swap_lv_size} ]] && { pxelog "[error]swap_lv_size is invalid: ${swap_lv_size} M!\n" "console"; return 1; }
[ $swap_lv_size -gt $free_storage ] && { pxelog "[error]free storage is $free_storage M, not enough for swap size($swap_lv_size M)!\n" "console"; return 1; }
sed -i "s/logvol swap.*/logvol swap --fstype swap --vgname=vg_sys --size=$swap_lv_size --name=lv_swap/" $KS_FILE
((pv_01=$swap_lv_size+$pv_01))
((free_storage=$free_storage-$swap_lv_size))
pxelog "swap_lv_size=${swap_lv_size} M, free_storage=$free_storage M"
#设置pv.01包括root_lv_size、swap_lv_size的冗余空间
sed -i "/\#end_part/i\part pv.01 --size=$pv_01 --ondisk=${root_disk}" $KS_FILE
pxelog "vg_sys_size equal to $pv_01 M"
sed -i "/cindervolumes/d" $KS_FILE
sed -i "/pv.02/d" $KS_FILE
sed -i "/pv.03/d" $KS_FILE
sed -i "/pv.04/d" $KS_FILE
pxelog "started custom_ks_vg_else!\n"
return 0
}
function custom_ks_vg
{
pxelog "starting custom_ks_vg!\n"
#对于我们自己的系统需要定制vg_data而对于其他的系统只要能将系统安装上就可以
if [[ $IS_TFG_ISO == "yes" ]]; then
custom_ks_vg_tfg $@ || return 1
else
custom_ks_vg_else $@ || return 1
fi
pxelog "started custom_ks_vg!\n"
return 0
}
# 定制ks中的绑核信息
function custom_ks_vmm
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_vmm!"
get_config $CFG_FILE "vmm_type"
vmtype=$config_answer
#liushn 目前vmm类型没有提供接口给上层进行配置都默认用kvm
if [ ! $vmtype = "xen" ];then
sed -i "s/dom0_mem=1024M dom0_max_vcpus=2//g" $KS_FILE
else
get_config $CFG_FILE "cpus"
xcpus=$config_answer
get_config $CFG_FILE "memsize"
xmemsize=$config_answer
sed -i "s/dom0_mem=1024M/dom0_mem=${xmemsize}M/g" $KS_FILE
sed -i "s/dom0_max_vcpus=2/dom0_max_vcpus=$xcpus/g" $KS_FILE
#sed -i "s/^RPCNFSDCOUNT=[0-9]*/RPCNFSDCOUNT=32/" $nfs_conf
fi
pxelog "started custom_ks_vmm!\n"
}
#定制安装完成后是否reboot
function custom_ks_reboot
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_reboot!"
get_config $CFG_FILE "reboot"
client_reboot=$config_answer
if [[ $client_reboot == "yes" ]] ;then
sed -i "s/^#*reboot/reboot/g" $KS_FILE
else
sed -i "s/^reboot/#reboot/g" $KS_FILE
fi
pxelog "started custom_ks_reboot!\n"
}
function custom_ks_hugepages
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_hugepages!"
get_config $CFG_FILE "hugepages"
pages=$config_answer
[[ $pages == "" ]] && pages=0
sed -i "s/pagevalue2/${pages}/g" $KS_FILE
get_config $CFG_FILE "hugepagesize"
sizes=$config_answer
[[ $sizes == "" ]] && sizes="1G"
[[ $sizes != "1G" && $sizes != "2M" ]] && { pxelog "[error]hugepagesize value error($sizes)" "console"; return 1; }
sed -i "s/pagevalue1/${sizes}/g" $KS_FILE
pxelog "started custom_ks_hugepages!\n"
}
function custom_ks_isolcpus
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_isolcpus!"
get_config $CFG_FILE "isolcpus"
isolcpus=$config_answer
if [[ $isolcpus != "" ]]; then
sed -i "s/isolvalue/${isolcpus}/g" $KS_FILE
else
sed -i "/isolvalue/d" $KS_FILE
fi
pxelog "started custom_ks_isolcpus!\n"
}
function custom_ks_hostname
{
local CFG_FILE=$1
local KS_FILE=$2
pxelog "starting custom_ks_hostname!"
get_config $CFG_FILE "hostname"
hostname=$config_answer
sed -i "/hostname/s/.*/echo \"${hostname}\"> \/etc\/hostname/" $KS_FILE
pxelog "started custom_ks_hostname!\n"
}
#检查nfs服务器的文件夹是否存在
function check_nfs_exports
{
local result=0
pxelog "starting check_nfs_exports!"
[ `cat /etc/exports | grep -c /home/install_share` -eq 0 ] && { pxelog "/home/install_share is not exported !" "console"; result=1; }
[ `cat /etc/exports | grep -c /tftpboot` -eq 0 ] && { pxelog "/tftpboot is not exported !" "console"; result=1; }
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
[ `cat /etc/exports | grep -c -w "/linuxinstall/linuxinstall_$i"` -eq 0 ] && { pxelog "/linuxinstall/linuxinstall_$i is not exported !" "console"; result=1; }
done
pxelog "started check_nfs_exports!\n"
return $result
}
#创建以目标安装机mac地址命名的共享文件夹用于mount iso、存放引导程序和ks文件等
#$1:json格式的配置文件
function custom_share_folder
{
local CFG_FILE=$1
local dhcp_mac
pxelog "starting custom_share_folder!"
#获取mac地址
get_config $CFG_FILE "dhcp_mac"
dhcp_mac=$config_answer
[[ -z $dhcp_mac || "0" = ${dhcp_mac} ]] && { pxelog "[error]dhcp_mac is null or 0" "console"; return 1; }
#将mac地址的:换成-
MACADDR=`echo $config_answer | sed "s/:/-/g"`
#/home/install_share下创建以mac地址命名的文件夹
INSTALLSHAREPATH=/home/install_share/${MACADDR}
rm -rf ${INSTALLSHAREPATH} 2>/dev/null
mkdir ${INSTALLSHAREPATH}
#/tftpboot下创建以mac地址命名的文件夹
rm -rf /tftpboot/pxelinux.cfg/01-${MACADDR}
rm -rf /tftpboot/${MACADDR} 2>/dev/null
mkdir /tftpboot/${MACADDR}
pxelog "started custom_share_folder!\n"
return 0
}
function repair_rsyslog_line
{
local file=$1
local string=$2
local result
local lineflag
local is_modify=0
result=`cat ${file} |grep "${string}"`
if [[ ${result} == "" ]]; then
lineflag=`grep -n "GLOBAL DIRECTIVES" ${file} | head -n 1 |awk -F':' '{print $1}'`
sed -i "${lineflag}i ${string}" ${file}
is_modify=1
else
result=`cat ${file} |grep "^[[:space:]]*${string}"`
if [[ ${result} == "" ]]; then
sed -i "s/.*${string}.*/${string}/g" ${file}
is_modify=1
fi
fi
return ${is_modify}
}
#设置/etc/rsyslog.conf,允许接收远程日志并且日志文件名以ip命名用以区分各个不同机器的日志
function custom_rsyslog
{
local rsyslog_cfg=/etc/rsyslog.conf
local is_modify=0
#判断UDP相关的配置是否打开
repair_rsyslog_line ${rsyslog_cfg} "\$ModLoad imudp" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "\$UDPServerRun 514" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "\$ModLoad imtcp" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "\$InputTCPServerRun 514" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "\$template IpTemplate,\"\/var\/log\/\%FROMHOST-IP\%.log\"" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "*.* \?IpTemplate" || is_modify=1
repair_rsyslog_line ${rsyslog_cfg} "\\& ~" || is_modify=1
[[ ${is_modify} -eq 1 ]] && { systemctl restart rsyslog.service; pxelog "rsyslog.conf repaired"; }
}
#判断是否tfg系统
function get_iso_type
{
IS_TFG_ISO="no";
#iso+bin形式表示是tfg系统
get_config $CFG_FILE "tfg_bin"
local TFG_BIN=$config_answer
[[ "${TFG_BIN}" != "" && -e "${TFG_BIN}" ]] && IS_TFG_ISO="yes"
#在ISOMOUNTPATH路径下判断是否有bin。
if [[ -d ${ISOMOUNTPATH} ]];then
local OS_TFG_BIN=${ISOMOUNTPATH}/*.bin
[ -e ${OS_TFG_BIN} ] && IS_TFG_ISO="yes"
fi
}
#处理os安装的一些预处理工作:包括创建和目标机mac地址相关的文件夹mount iso拷贝ISO中的引导程序到根目录拷贝ks文件、网口固化脚本文
#$1:json格式的配置文件
#$2:安装配置文件的路径
function custom_pre_cfg
{
local CFG_FILE=$1
local ISOPATH
local WORKDIR=$2
local dhcp_mac
local INSTALL_LOG
pxelog "starting custom_pre_cfg!"
#创建以目标安装机mac地址命名的共享文件夹用于mount iso、存放引导程序和ks文件等
custom_share_folder ${CFG_FILE} || return 1
pxelog "MACADDR=${MACADDR}"
pxelog "INSTALLSHAREPATH=${INSTALLSHAREPATH}"
#获取iso文件
get_config $CFG_FILE "iso_path"
ISOPATH=${config_answer}
[[ -z ${ISOPATH} ]] && { pxelog "[error]iso_path is null !" "console"; return 1; }
[[ ! -e ${ISOPATH} ]] && { pxelog "[error]iso_path ${ISOPATH} not exist !" "console"; return 1; }
#确认iso的挂载点
rm -rf /usr/lib/systemd/system/linuxinstall.mount 2>/dev/nul
ISOMOUNTPATH=`mount |grep -w $ISOPATH | grep -w "/linuxinstall/linuxinstall_[0-9]*" |head -n 1| awk -F' ' '{print $3}'`
#如果没有找到iso的挂载点那么需要选择一个未用的/linuxinstall/linuxinstall_n进行挂载
if [[ ${ISOMOUNTPATH} == "" ]]; then
for (( i=1; i<=$ISO_MOUNT_DIR_NUM; i++))
do
if [[ `mount |grep -w "/linuxinstall/linuxinstall_$i"` == "" ]]; then
ISOMOUNTPATH=/linuxinstall/linuxinstall_$i
#mount iso
mount -t iso9660 ${ISOPATH} ${ISOMOUNTPATH} -o loop
repir_iso_nfs_number $MACADDR ${ISOMOUNTPATH} "clean" || return 1
break
fi
done
fi
#所有的/linuxinstall/linuxinstall_*用完了就报错否则将ISOMOUNTPATH的使用数加1
if [[ ${ISOMOUNTPATH} == "" ]]; then
pxelog "[error]all /linuxinstall/linuxinstall_n are used, iso can't be mounted !" "console"
return 1
else
pxelog "ISOMOUNTPATH=${ISOMOUNTPATH}!"
#生成linuxinstall-linuxinstall_$i.mount并且使能
local linuxinstall_mount=`basename ${ISOMOUNTPATH}`
linuxinstall_mount="linuxinstall-""${linuxinstall_mount}"".mount"
linuxinstall_mount_unit=/lib/systemd/system/$linuxinstall_mount
pxelog "linuxinstall mount unit file=$linuxinstall_mount_unit !"
cp -rf ${WORKDIR}/pxe/linuxinstall.mount $linuxinstall_mount_unit
sed -i "s:What.*:What=${ISOPATH}:g" $linuxinstall_mount_unit
sed -i "s:Where.*:Where=${ISOMOUNTPATH}:g" $linuxinstall_mount_unit
systemctl enable $linuxinstall_mount &>/dev/null
#修改ISOMOUNTPATH的使用数
repir_iso_nfs_number $MACADDR ${ISOMOUNTPATH} "add" || return 1
fi
#判断是否tfg系统
get_iso_type
# 拷贝内核和启动程序到为目标机创建的根目录,拷贝完需要umount
\cp -f /${ISOMOUNTPATH}/isolinux/initrd.img /tftpboot/${MACADDR}/
\cp -f /${ISOMOUNTPATH}/isolinux/vmlinuz /tftpboot/${MACADDR}/
# 拷贝pxe的引导程序到根目录
[ ! -e /tftpboot/pxelinux.0 ] && { \cp -f /usr/share/syslinux/pxelinux.0 /tftpboot; }
#kickstart 拷贝出来方便以后可不更换ISO修改kickstart
rm -rf ${INSTALLSHAREPATH}/*
\cp -f ${WORKDIR}/pxe/pxe_kickstart.cfg ${INSTALLSHAREPATH}/
\cp -rf ${WORKDIR}/usrdata ${INSTALLSHAREPATH}/ &>/dev/null
\cp -rf ${WORKDIR}/scripts/custom ${INSTALLSHAREPATH}/ &>/dev/null
rm -rf ${INSTALLSHAREPATH}/custom/interact* &>/dev/null
\cp -f ${CFG_FILE} ${INSTALLSHAREPATH}/os.json
#拷贝tfg的bin文件到INSTALLSHAREPATH下面
get_config $CFG_FILE "tfg_bin"
tfg_bin=$config_answer
[[ ! -z ${tfg_bin} && -e ${tfg_bin} ]] && { pxelog "tfg_bin exist!\n"; \cp -f ${tfg_bin} ${INSTALLSHAREPATH}/; }
#在/var/log/pxe_os_table.log下记录这个目标机
[ ! -f $PXE_OS_TAB ] && { touch $PXE_OS_TAB; }
[[ `cat $PXE_OS_TAB |grep "${MACADDR}"` == "" ]] && { echo "${MACADDR} 0 plan_install ${ISOMOUNTPATH}" >>$PXE_OS_TAB; } \
|| { sed -i "s%${MACADDR} .*%${MACADDR} 0 plan_install ${ISOMOUNTPATH}%g" $PXE_OS_TAB; }
#网口固化和网络配置的脚本拷贝出来用于后续根据jason文件定制固化规则以及网口配置
\cp -f ${WORKDIR}/scripts/nic_net_cfg.sh ${INSTALLSHAREPATH}/usrdata/
#服务器启动接收远程日志的功能,用于接收目标机安装过程中的日志
custom_rsyslog
#清空目标机所有的历史日志记录
get_config $CFG_FILE "dhcp_mac"
dhcp_mac=$config_answer
clean_mac_all_log ${dhcp_mac}
pxelog "started custom_pre_cfg!\n"
return 0
}
#生成default文件
function custom_default_cfg
{
local CFG_FILE=$1
local WORKDIR=$2
local DEFAULT_CFG=/tftpboot/pxelinux.cfg/01-${MACADDR}
local KS_FILE=${INSTALLSHAREPATH}/pxe_kickstart.cfg
pxelog "starting custom_default_cfg!"
#拷贝default文件到/tftpboot/pxelinux.cfg文件夹并且改成以mac地址命名的文件
[ ! -d /tftpboot/pxelinux.cfg ] && { mkdir -p /tftpboot/pxelinux.cfg; }
cp -rf ${WORKDIR}/pxe/default ${DEFAULT_CFG}
#获取pxe服务器的监听地址
local svrip=`cat /etc/dhcp/dhcpd.conf | grep next-server |awk -F' ' '{print $2}' |sed "s/;//"`
#修改defult文件涉及kernel文件和initrd相对于/tftpboot的存放位置ks文件存放位置
sed -i "s%kernel vmlinuz%kernel ${MACADDR}/vmlinuz%g" ${DEFAULT_CFG}
sed -i "s%initrd=initrd.img%initrd=${MACADDR}/initrd.img%g" ${DEFAULT_CFG}
sed -i "s%nfs:.*:.*pxe_kickstart.cfg%nfs:$svrip:${KS_FILE}%g" ${DEFAULT_CFG}
pxelog "started custom_default_cfg!\n"
return 0
}
function custom_ks_server_ip
{
local KS_FILE=$1
pxelog "starting custom_ks_server_ip!"
#获取pxe服务器的监听地址
local svrip=`cat /etc/dhcp/dhcpd.conf | grep next-server |awk -F' ' '{print $2}' |sed "s/;//"`
#修改ks文件中nfs服务器ip
sed -i "s/ntpdate -s.*/ntpdate -s $svrip\" >> \/var\/spool\/cron\/root/g" $KS_FILE
sed -i "s%nfs --server=.*--dir=%nfs --server=$svrip --dir=%g" $KS_FILE
sed -i "s/NFS_SERVER_ADDRESS=.*/NFS_SERVER_ADDRESS=$svrip/g" $KS_FILE
#修改ks文件中logging主机ip
sed -i "s/logging --host=.*--level=/logging --host=$svrip --port=514 --level=/g" $KS_FILE
pxelog "started custom_ks_server_ip!\n"
return 0
}
function custom_ks_nfs_dir
{
local KS_FILE=$1
pxelog "starting custom_ks_nfs_dir!"
#修改ks文件中和目标机mac地址相关的文件夹或者目录
sed -i "s%macaddr%${MACADDR}%g" $KS_FILE
#修改ks文件中iso挂载点
sed -i "s%iso_nfs_dir%${ISOMOUNTPATH}%g" $KS_FILE
pxelog "started custom_ks_nfs_dir!\n"
return 0
}
#######################
#从json配置文件读取网口相关参数并且修改网口固化和网口配置脚本NET_FILE改写ks文件在post阶段执行NET_FILE
#######################
function custom_ks_net_config
{
local CFG_FILE=$1
local KS_FILE=$2
local NET_FILE=$3
pxelog "starting custom_ks_net_config!"
[ ! -e $CFG_FILE ] && { pxelog "[error]file ${CFG_FILE} not exist!" "console"; return 1; }
[ ! -e $KS_FILE ] && { pxelog "[error]file ${KS_FILE} not exist!" "console"; return 1; }
[ ! -e $NET_FILE ] && { pxelog "[error]file ${NET_FILE} not exist!" "console"; return 1; }
local length=$(cat $CFG_FILE | jq '.interfaces[].name' | wc -l)
pxelog "interfaces length=$length"
for (( i=0; i<length; i++))
do
pxelog "interface[$i]"
get_config $CFG_FILE "interfaces[$i].name"
local eth_name=$config_answer
get_config $CFG_FILE "interfaces[$i].type"
local eth_type=$config_answer
get_config $CFG_FILE "interfaces[$i].pci"
local eth_pci=$config_answer
local eth_gateway=""
local eth_ip=""
local eth_netmask=""
local management_gateway=""
local management_ip=""
local management_netmask=""
local network_type=""
local vlan_id=""
#从interfaces[$i]中获取管理面的ip、netmask、gateway
local length2=$(cat $CFG_FILE | jq ".interfaces[$i].assigned_networks[].network_type" | wc -l)
pxelog "assigned_networks length=$length2"
if [ $length2 -eq 0 ];then
network_type="MANAGEMENT"
else
for (( j=0; j<length2; j++))
do
get_config $CFG_FILE "interfaces[$i].assigned_networks[$j].network_type"
network_type=$config_answer
if [[ $network_type = "MANAGEMENT" ]]; then
get_config $CFG_FILE "interfaces[$i].assigned_networks[$j].ip"
management_ip=$config_answer
get_config $CFG_FILE "interfaces[$i].assigned_networks[$j].netmask"
management_netmask=$config_answer
get_config $CFG_FILE "interfaces[$i].assigned_networks[$j].gateway"
management_gateway=$config_answer
get_config $CFG_FILE "interfaces[$i].assigned_networks[$j].vlan_id"
vlan_id=$config_answer
break 1
fi
done
fi
#只对管理口配置ip、netmask、gateway
if [[ $network_type = "MANAGEMENT" ]]; then
get_config $CFG_FILE "interfaces[$i].ip"
eth_ip=$config_answer
get_config $CFG_FILE "interfaces[$i].netmask"
eth_netmask=$config_answer
get_config $CFG_FILE "interfaces[$i].gateway"
eth_gateway=$config_answer
# 先判断interfaces[$i]的ip、netmask是否为空如果为空就用管理面配置的ip、netmask、gateway
# 如果管理面的ip、netmask也为空那么就报错返回1
if [[ $eth_ip = "" || $eth_netmask = "" ]]; then
if [ $management_ip = "" -o $management_netmask = "" -a $length2 -ne 0 ]; then
pxelog "[error]interfaces[$i] ip/netmask is null, please check!" "console"
return 1
else
eth_ip=$management_ip
eth_netmask=$management_netmask
eth_gateway=$management_gateway
fi
fi
fi
pxelog "eth_name=$eth_name"
pxelog "eth_type=$eth_type"
pxelog "eth_pci=$eth_pci"
pxelog "eth_ip=$eth_ip"
pxelog "eth_netmask=$eth_netmask"
pxelog "eth_gateway=$eth_gateway"
pxelog "network_type=$network_type"
pxelog "vlan_id=$vlan_id"
#在NET_FILE 后面追加第i个网口的网口固化规则和网口配置
echo "#config $eth_name" >> $NET_FILE
#如果网口类型是ether那么直接做网口配置
if [[ $eth_type = "ether" ]];then
echo "eth_nicfix \"$eth_name\" \"$eth_pci\"" >> $NET_FILE
if [[ $vlan_id != "" ]]; then
echo "vlan_config \"$eth_name\" \"$vlan_id\" \"$eth_ip\" \"$eth_netmask\" \"$eth_gateway\"" >> $NET_FILE
echo "eth_config \"$eth_name\" \"\" \"\" \"\" \"\"" >> $NET_FILE
else
echo "eth_config \"$eth_name\" \"$eth_ip\" \"$eth_netmask\" \"$eth_gateway\" \"\"" >> $NET_FILE
fi
fi
#如果网口类型是bond且有管理面那么做bond配置
if [[ $eth_type = "bond" && $network_type = "MANAGEMENT" ]];then
get_config $CFG_FILE "interfaces[$i].mode"
local eth_mode=$config_answer
get_config $CFG_FILE "interfaces[$i].slave1"
local eth_slave1=$config_answer
get_config $CFG_FILE "interfaces[$i].slave2"
local eth_slave2=$config_answer
pxelog "eth_mode=$eth_mode"
pxelog "eth_slave1=$eth_slave1"
pxelog "eth_slave2=$eth_slave2"
if [[ $vlan_id != "" ]]; then
echo "vlan_config \"$eth_name\" \"$vlan_id\" \"$eth_ip\" \"$eth_netmask\" \"$eth_gateway\"" >> $NET_FILE
echo "bond_config \"$eth_name\" \"\" \"\" \"\" \"$eth_mode\" \"$eth_slave1\" \"$eth_slave2\"" >> $NET_FILE
else
echo "bond_config \"$eth_name\" \"$eth_ip\" \"$eth_netmask\" \"$eth_gateway\" \"$eth_mode\" \"$eth_slave1\" \"$eth_slave2\"" >> $NET_FILE
fi
fi
echo >> $NET_FILE
done
pxelog "started custom_ks_net_config!\n"
return 0
}
#添加package组非tfg版本添加Base组。tfg版本仅仅使用Core组
function custom_ks_package_group
{
local CFG_FILE=$1
local KS_FILE=$2
#非tfg版本添加Base组
pxelog "starting custom_ks_package_group!\n"
get_config $CFG_FILE "group_list"
group_list=$config_answer
group_list_array=`echo ${group_list} |sed "s/,/ /g"`
pxelog "group_list_array=${group_list_array}"
if [[ $IS_TFG_ISO != "yes" ]] ;then
for i in ${group_list_array}
do
if [[ $i != "Core" ]];then
sed -i "/\@Core/a\@$i" $KS_FILE ;
pxelog "add @$i in %packages of pxe_kickstart.cfg"
fi
done
fi
pxelog "started custom_ks_package_group!\n"
return 0
}
#生成ks文件
function custom_ks_cfg
{
local CFG_FILE=$1
local KS_FILE=${INSTALLSHAREPATH}/pxe_kickstart.cfg
local NET_FILE=${INSTALLSHAREPATH}/usrdata/nic_net_cfg.sh
pxelog "starting custom_ks_cfg!"
custom_ks_server_ip $KS_FILE
custom_ks_nfs_dir $KS_FILE
custom_ks_rootpwd $CFG_FILE $KS_FILE
custom_ks_vg $CFG_FILE $KS_FILE || return 1
custom_ks_vmm $CFG_FILE $KS_FILE
custom_ks_reboot $CFG_FILE $KS_FILE
custom_ks_hugepages $CFG_FILE $KS_FILE || return 1
custom_ks_hostname $CFG_FILE $KS_FILE
custom_ks_net_config $CFG_FILE $KS_FILE $NET_FILE || return 1
custom_ks_isolcpus $CFG_FILE $KS_FILE
custom_ks_package_group $CFG_FILE $KS_FILE
pxelog "started custom_ks_cfg!\n"
return 0
}

View File

@ -0,0 +1,2 @@
说明:
放在此目录中的文件,都将自动拷贝到安装系统后的目标机的/home/usrdata目录

View File

@ -0,0 +1,78 @@
#!/bin/bash
###############################################################################################
# 功能搭建pxe服务器 定制和搭建的脚本运行时拷贝过来,执行后删除 dirname $0
# 用户交互数据保存在pxe_env.conf中
###############################################################################################
function showhelp
{
echo -e "Usage1: $0 config_file_path"
echo -e "Options:"
echo -e " config_file_path: json file path that contain customized config about os install"
echo -e " (json file format is as /etc/pxe_install/json_format/os.json)"
echo ""
echo -e "Usage2: $0 --help display this help and exit"
echo ""
}
function main_install
{
local CFG_FILE=$1
local WORKDIR=$2
#检查nfs服务器的文件夹是否存在
check_nfs_exports || { pxelog "[error]nfs server not correct installed, please reinstall !" "console"; return 1; }
#处理os安装的一些预处理工作:包括创建和目标机mac地址相关的文件夹mount iso拷贝ISO中的引导程序到根目录拷贝ks文件、网口固化脚本文件
custom_pre_cfg ${CFG_FILE} ${WORKDIR} || return 1
#生成default文件
custom_default_cfg ${CFG_FILE} ${WORKDIR}
#生成以及配置ks文件
custom_ks_cfg ${CFG_FILE} || return 1
return 0
}
# ##############################################################################################
# 入口 #
# ##############################################################################################
#工作目录定义及检查
WORKDIR=/etc/pxe_install
[ ! -d ${WORKDIR} ] && { pxelog "[error]WORKDIR ${WORKDIR} not exist!" "console"; exit 1; }
source ${WORKDIR}/scripts/common.sh
source ${WORKDIR}/scripts/setup_func.sh
is_fail=0
pxelog "********************begin pxe os install********************" "console"
#显示帮助提示
if [[ `echo $* |grep -wi 'help'` != "" ]];then
showhelp
exit 0
fi
#入参检查
[ $# != 1 ] && { pxelog "[error]Param num fail, please input again" "console"; showhelp; exit 1; }
CFG_FILE=$1
[ ! -e ${CFG_FILE} ] && { pxelog "[error]file ${CFG_FILE} not exist!" "console"; exit 1; }
#开始安装
main_install ${CFG_FILE} ${WORKDIR} || is_fail=1
pxelog "********************end pxe os install********************\n" "console"
pxelog "************************************************************" "console"
if [ $is_fail -eq 0 ]; then
pxelog "good! pxe os install config has been finished!" "console"
pxelog "now you can enjoy installing os by pxe server" "console"
else
pxelog "failed! pxe os install config encounter error!" "console"
pxelog "please check and reinstall" "console"
fi
pxelog "************************************************************" "console"
exit $is_fail

View File

@ -0,0 +1,60 @@
#!/bin/bash
###############################################################################################
# 功能:清除服务器上某个目标机的痕迹
###############################################################################################
function showhelp
{
echo -e "Usage1: $0 target_machine_macaddr"
echo -e "Options:"
echo -e " target_machine_macaddr: the interface mac address of the target machine which link to pxe server "
echo ""
echo -e "Usage2: $0 all clean all os files"
echo -e "Usage3: $0 --help display this help and exit"
echo ""
}
# ##############################################################################################
# 入口 #
# ##############################################################################################
#工作目录定义及检查
WORKDIR=/etc/pxe_install
[ ! -d ${WORKDIR} ] && { pxelog "[error]WORKDIR ${WORKDIR} not exist!" "console"; exit 1; }
source ${WORKDIR}/scripts/common.sh
pxelog "********************clean os install info($1)********************"
#显示帮助提示
if [[ `echo $* |grep -wi 'help'` != "" ]];then
showhelp
exit 0
fi
#入参检查
[ $# != 1 ] && { pxelog "[error]Param num fail, please input again" "console"; showhelp; exit 1; }
#取入参如果是all那么清除所有目标机的痕迹如果是mac地址那么只清除一台目标机的痕迹
param=$1
if [ ${param} = "all" ]; then
#删除pxe服务器上目标机相关的文件
clean_all_os_files
#清空目标机所有的历史日志记录
clean_all_log
#清除pxe服务器os安装统计表
rm -rf $PXE_OS_TAB
else
#将mac地址的:换成-
dhcp_mac=$1
MACADDR=`echo ${dhcp_mac} | sed "s/:/-/g"`
#删除pxe服务器上目标机相关的文件
clean_os_files ${MACADDR} ${PXE_OS_TAB}
#清除pxe服务器os安装统计表中关于目标机安装的信息
clean_os_table ${MACADDR} ${PXE_OS_TAB}
fi
exit 0

View File

@ -0,0 +1,57 @@
#!/bin/bash
###############################################################################################
# 功能获取os安装进度并且打印出来
###############################################################################################
function showhelp
{
echo -e "Usage1: $0 target_machine_macaddr"
echo -e "Options:"
echo -e " target_machine_macaddr: the interface mac address of the target machine which link to pxe server "
echo ""
echo -e "Usage2: $0 --help display this help and exit"
echo ""
}
# ##############################################################################################
# 入口 #
# ##############################################################################################
#工作目录定义及检查
WORKDIR=/etc/pxe_install
[ ! -d ${WORKDIR} ] && { pxelog "[error]WORKDIR ${WORKDIR} not exist!" "console"; exit 1; }
source ${WORKDIR}/scripts/common.sh
source ${WORKDIR}/scripts/query_progress.sh
pxelog "********************query os install progress********************"
#显示帮助提示
if [[ `echo $* |grep -wi 'help'` != "" ]];then
showhelp
exit 0
fi
#入参检查
[ $# != 1 ] && { pxelog "[error]Param num fail, please input again" "console"; showhelp; exit 1; }
#将mac地址的:换成-
dhcp_mac=$1
MACADDR=`echo ${dhcp_mac} | sed "s/:/-/g"`
#pxe服务器上os安装的统计表
[ ! -f ${PXE_OS_TAB} ] && { pxelog "[error]can not find os table in pxe server"; exit 1; }
#先在统计表中查一下目标机记录,如果没有表示没有配置过目标机
if [[ `cat ${PXE_OS_TAB} |grep -wi "${MACADDR}"` == "" ]]; then
pxelog "0 not_plan_install" "console"
pxelog "the target machine is not configed in pxe server, please use pxe_os_install for configuration!"
exit 0
fi
#由mac地址映射到ip地址以及找到存放该目标机安装日志的log文件若找不到对应的ip那么表示还未开始安装
convert_mac_to_ip ${dhcp_mac} || { pxelog "0 plan_install" "console";exit 0; }
INSTALL_LOG=${install_log}
#分析日志,得到安装进度以及正在做什么事情
get_progress ${INSTALL_LOG} ${PXE_OS_TAB} ${MACADDR}
exit 0

View File

@ -0,0 +1,380 @@
#!/bin/bash
function display_install_status
{
echo "===================display install status==================="
begin_time="${1}"
discovered_macaddr="${2}"
installing_macaddr="${3}"
installed_macaddr="${4}"
interface="${5}"
dhcpd_log=`journalctl --unit=dhcpd --since="$begin_time"`
request_macaddr=`echo -e "$dhcpd_log" | grep "DHCPDISCOVER" | grep "via $interface" | awk -F'via' '{print $1}' | awk '{print $NF}' | sort -u`
offer_macaddr=`echo -e "$dhcpd_log" | grep "DHCPOFFER" | grep "via $interface" | awk '{print $10}' | sort -u`
echo "request for dhcp hosts:"
for each in $request_macaddr
do
echo " $each"
done
echo
echo "discovered hosts:"
for each in $discovered_macaddr
do
echo " $each"
done
echo
echo "installing hosts:"
for each in $installing_macaddr
do
echo " $each"
done
echo
echo "installed hosts:"
for each in $installed_macaddr
do
echo " $each"
done
echo
}
function check_server_rpms
{
echo "checking server rpms..."
[ `rpm -qa xinetd` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm xinetd not installed"; exit 1; }
[ `rpm -qa tftp-server` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm tftp-server not installed"; exit 1; }
[ `rpm -qa tftp` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm tftp not installed"; exit 1; }
[ `rpm -qa ipxe-roms-qemu` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm ipxe-roms-qemu not installed"; exit 1; }
[ `rpm -qa syslinux` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm syslinux not installed"; exit 1; }
[ `rpm -qa dhcp-common` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm dhcp-common not installed"; exit 1; }
[ `rpm -qa dhcp` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm dhcp not installed"; exit 1; }
[ `rpm -qa ntpdate` ] || { echo -e "\e[31;1m[Warning]\e[0mrpm ntpdate not installed"; exit 1; }
}
function check_service_status
{
echo "checking service status..."
local status=""
status=`systemctl is-active iptables`
if [[ "$status" == "active" || "$status" == "reloading" || "$status" == "activating" ]];then
echo -e "\e[31;1m[Warning]\e[0miptables.service is active, use 'systemctl status iptables' for details"
exit 1
fi
status=""
status=`systemctl is-active firewalld`
if [[ "$status" == "active" || "$status" == "reloading" || "$status" == "activating" ]];then
echo -e "\e[31;1m[Warning]\e[0mfirewalld.service is active, use 'systemctl status firewalld' for details"
exit 1
fi
status=""
status=`systemctl is-active xinetd`
if [[ "$status" != "active" && "$status" != "reloading" && "$status" != "activating" ]];then
echo -e "\e[31;1m[Warning]\e[0mxinetd.service is inactive, use 'systemctl status xinetd' for details"
exit 1
fi
status=""
status=`systemctl is-active nfs-server`
if [[ "$status" != "active" && "$status" != "reloading" && "$status" != "activating" ]];then
echo -e "\e[31;1m[Warning]\e[0mnfs-server.service is inactive, use 'systemctl status nfs-server' for details"
exit 1
fi
status=""
status=`systemctl is-active dhcpd`
if [[ "$status" != "active" && "$status" != "reloading" && "$status" != "activating" ]];then
echo -e "\e[31;1m[Warning]\e[0mdhcpd.service is inactive, use 'systemctl status dhcpd' for details"
exit 1
fi
}
function check_multi_dhcp_server
{
echo "checking other dhcp server..."
local interface=$1
if [[ `systemctl list-unit-files |grep -w dhcpd.service` != "" ]]; then
[[ `systemctl is-enabled dhcpd.service` != "enabled" ]] && dhcpd_is_enable="disabled" || dhcpd_is_enable="enabled"
[[ `systemctl is-active dhcpd.service` != "active" ]] && dhcpd_is_active="inactive" || dhcpd_is_active="active"
fi
systemctl disable dhcpd.service >/dev/null
systemctl stop dhcpd.service >/dev/null
tcpdump -i $interface -e udp port 67 -n -vv 1>./dhcplog 2>/dev/null &
nmap -e $interface --script broadcast-dhcp-discover &> /dev/null
sleep 17
pid=`ps -def | grep "tcpdump -i $interface -e udp port 67 -n -vv" | grep -v grep |grep tcpdump | awk '{print $2}'`
[[ -n "$pid" ]] && kill $pid > /dev/null
sleep 3
while :
do
pid=`ps -def | grep "tcpdump -i $interface -e udp port 67 -n -vv" | grep -v grep |grep tcpdump | awk '{print $2}'`
[[ -n "$pid" ]] && kill $pid > /dev/null && sleep 2 || break
done
server_ips=`cat ./dhcplog | grep "Server-ID Option 54" | awk -F ': ' '{print $2}'`
if [[ -n "$server_ips" ]];then
local i=1
echo -e "\e[31;1m[Warning]\e[0mthere are other dhcp servers in the network"
for one in $server_ips
do
server_ip=`echo $server_ips | awk -v N=$i '{printf "%-15s\n", $N}'`
echo "$i. $server_ip"
let i++
done
exit 1
fi
rm -f ./dhcplog
[[ $dhcpd_is_enable == "enabled" ]] && systemctl enable dhcpd.service >/dev/null
[[ $dhcpd_is_active == "active" ]] && systemctl restart dhcpd.service >/dev/null
}
#检查网口是不是有ip并且为RUNNING状态
function check_interface
{
echo "checking interface ${1}..."
local nic4dhcp="${1}"
local ipaddr="${2}"
status=`ifconfig "${nic4dhcp}:100" 2>/dev/null | grep "RUNNING" -A 2 | grep "$ipaddr"`
if [ -z "$status" ];then
echo -e "\e[31;1m[Warning]\e[0minterface "${nic4dhcp}:100" is not up!"
exit 1
fi
}
function check_ip_conflict
{
echo "checking ip conflict..."
local interface=$1
local ip_addr=$2
local result=`arping -w 2 -D -I ${interface} ${ip_addr}`
if [ -n "`echo "${result}" | grep "Unicast reply from ${ip_addr}"`" ];then
echo -e "\e[31;1m[Warning]\e[0mip-address conflicts, there is other interface with ip ${ip_addr}"
echo -e "${result}"
exit 1
fi
}
function check_file_and_directory
{
echo "checking file and directory..."
local MACADDR=`echo -e "$1" | sed s/:/-/g`
local TFTPDIR=/tftpboot
local INSTALLSHARE=/home/install_share
local LINUXINSTALL=/linuxinstall
local flag=0
[ -f $TFTPDIR/initrd.img ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/initrd.img missing"
[ -f $TFTPDIR/vmlinuz ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/vmlinuz missing"
[ -f $TFTPDIR/pxelinux.0 ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/pxelinux.0 missing"
[ -f $TFTPDIR/pxelinux.cfg/default ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/pxelinux.cfg/default missing"
if [ -n "${MACADDR}" ];then
for each in $MACADDR
do
#if [ -n "`cat $INSTALL_LOG | grep "MACADDR=${each}"`" ];then
[ -f $TFTPDIR/$each/initrd.img ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/$each/initrd.img missing"
[ -f $TFTPDIR/$each/vmlinuz ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/$each/vmlinuz missing"
[ -f $TFTPDIR/pxelinux.cfg/01-${each} ] || echo -e "\e[31;1m[Warning]\e[0mfile $TFTPDIR/pxelinux.cfg/01-$each missing"
[ -f $INSTALLSHARE/$each/os.json ] || echo -e "\e[31;1m[Warning]\e[0mfile $INSTALLSHARE/$each/os.json missing"
[ -f $INSTALLSHARE/$each/pxe_kickstart.cfg ] || echo -e "\e[31;1m[Warning]\e[0mfile $INSTALLSHARE/$each/pxe_kickstart.cfg missing"
[ -d $INSTALLSHARE/$each/custom ] || echo -e "\e[31;1m[Warning]\e[0mdirectory $INSTALLSHARE/$each/custom missing"
[ -d $INSTALLSHARE/$each/usrdata ] || echo -e "\e[31;1m[Warning]\e[0mdirectory $INSTALLSHARE/$each/usrdata missing"
#fi
done
fi
}
function check_nfs_server
{
echo "checking nfs server..."
local result=`showmount -e`
local flag=0
[ "`echo -e "$result" | grep "/home/install_share"`" ] || flag=1
[ "`echo -e "$result" | grep "/tftpboot"`" ] || flag=1
[ "`echo -e "$result" | grep "/linuxinstall"`" ] || flag=1
[ $flag -eq 1 ] && { echo -e "\e[31;1m[Warning]\e[0mnfs server failed, directory is not shared, use 'showmount -e' for details"; exit 1; }
}
function check_os_json_file
{
echo "checking os json file..."
local MACADDR=`echo -e "$1" | sed s/:/-/g`
if [ -n "${MACADDR}" ];then
for each in $MACADDR
do
#if [ -n "`cat $INSTALL_LOG | grep "MACADDR=${each}"`" ];then
local JSON_FILE=/home/install_share/${each}/os.json
[ -e $JSON_FILE ] || return 1
local flag=0
local result=`cat $JSON_FILE | grep disk_list`
[ -n "`echo "$result" | grep "multi"`" ] && { echo -e "\e[31;1m[Warning]\e[0mdisk list in file $JSON_FILE error, ${result}"; exit 1; }
#fi
done
fi
}
#获取daisy服务器的网口和ip地址
function get_server_interface_and_ip
{
local Log_File="$INSTALL_LOG"
local begin_flag="begin pxe server install"
local end_flag="end pxe server install"
log_fragment=""
begin_line=`cat $Log_File -n | grep "$begin_flag" | tail -n 1 | awk '{print $1}'`
end_line=`cat $Log_File -n | grep "$end_flag" | tail -n 1 | awk '{print $1}'`
[ -z "$begin_line" ] && echo "[error]no pxe server install log" && exit 0
[ -z "$end_line" ] && echo "[error]no pxe server install log" && exit 0
if [ "$begin_line" -gt "$end_line" ];then
echo "[error]no pxe server install log"
exit 0
fi
log_fragment=`sed -n "$begin_line,$end_line p" ${Log_File}`
ethname_l=`echo -e "${log_fragment}" | grep "ethname_l" | tail -n 1 | awk -F '=' '{print $2}'`
ip_addr_l=`echo -e "${log_fragment}" | grep "ip_addr_l" | tail -n 1 | awk -F '=' '{print $2}'`
}
#获取目标机的mac地址
function get_macaddr
{
local result=`ironic physical-node-list`
local mac_addr=`echo -e "$result" | grep -E [0-9,A-F,a-f]{2}: | awk '{print $6}'`
#local mac_addr=`sed -n "$end_line,$ p" ${Log_File} | grep -E MACADDR=.*[0-9,A-F,a-f]{2}$ |awk -F 'MACADDR=' '{print $2}'`
#macaddr=""
#echo -e "$mac_addr"
discovered_macaddr=`echo -e "${mac_addr}" | sort`
installing_macaddr=`echo -e "${mac_addr}" | sort`
if [ -n "${mac_addr}" ];then
for each in $mac_addr
do
#if [ -z "`sed -n "$end_line,$ p" ${Log_File} | grep -A1 "${each}" | tail -n 1 | grep "install complete, will clean files"`" ];then
temp_mac=`echo ${each} | sed s/:/-/g`
if [[ "`cat $OS_TABLE_LOG | grep ${temp_mac} | awk '{print $2}'`" == "100" ]];then
if [ -z "$installed_macaddr" ];then
installed_macaddr=${each}
else
installed_macaddr="$installed_macaddr\n${each}"
fi
installing_macaddr=`echo -e "${installing_macaddr}" | sed /${each}/d`
fi
#temp_mac=`echo ${each} | sed s/:/-/g`
#echo installing_macaddr=$installing_macaddr
if [ -z "`cat $INSTALL_LOG | grep "MACADDR=${temp_mac}"`" ];then
installing_macaddr=`echo -e "${installing_macaddr}" | sed /${each}/d`
#echo installing_macaddr=$installing_macaddr
fi
done
#installing_macaddr="${mac_addr}"
#echo $macaddr
#echo discovered_macaddr=$discovered_macaddr
#echo installed_macaddr=$installed_macaddr
#echo installing_macaddr=$installing_macaddr
fi
}
#获取daisy服务器安装的时间
function get_server_install_time
{
local begin_time=`cat $INSTALL_LOG | grep "begin pxe server install" | tail -n 1 | cut -c1-15`
server_install_time=`date -d "${begin_time}" "+%Y-%m-%d %H:%M:%S"`
}
#从环境中获取配置文件,供之后的检查函数使用
function get_config
{
get_server_interface_and_ip
get_macaddr
get_server_install_time
}
function check_daisy_server
{
display_install_status "$server_install_time" "$discovered_macaddr" "$installing_macaddr" "$installed_macaddr" "${ethname_l}"
echo "===================checking daisy server==================="
echo
check_server_rpms
check_service_status
check_interface "${ethname_l}" "${ip_addr_l}"
check_multi_dhcp_server "${ethname_l}"
check_ip_conflict "${ethname_l}" "${ip_addr_l}"
check_nfs_server
check_file_and_directory "${installing_macaddr}"
check_os_json_file "${installing_macaddr}"
echo
echo -e "\e[31;1mif the check passed but still with errors, please check the network\e[0m"
}
function collect_log
{
begin_time="$server_install_time"
local LOGDIR=/var/log/tfg/pxechecktools
[ -d ${LOGDIR} ] && rm -rf ${LOGDIR}
mkdir -p ${LOGDIR}
cp /var/lib/dhcpd/dhcpd.leases ${LOGDIR}
journalctl --unit=dhcpd --since="$begin_time" > ${LOGDIR}/journalctl.dhcpd.log
}
#检查运行脚本需要的rpm包
function prepare_for_tools
{
rpm -qi nmap >/dev/null
if [ $? -ne 0 ];then
yum -y install nmap >/dev/null 2>&1 || { echo "[Error] Please install rpm of nmap and run the script again"; exit 1; }
fi
rpm -qi tcpdump >/dev/null
if [ $? -ne 0 ];then
yum -y install tcpdump >/dev/null 2>&1 || { echo "[Error] Please install rpm of tcpdump and run the script again"; exit 1; }
fi
rpm -qi nfs-utils >/dev/null
if [ $? -ne 0 ];then
yum -y install nfs-utils >/dev/null 2>&1 || { echo "[Error] Please install rpm of nfs-utils and run the script again"; exit 1; }
fi
}
#===============================================================================
#=====================================start=====================================
#===============================================================================
INSTALL_LOG=/var/log/pxe_install.log
OS_TABLE_LOG=/var/log/pxe_os_table.log
[ -e /root/daisyrc_admin ] && source /root/daisyrc_admin || { echo "[error]file /root/daisyrc_admin missing"; exit 1; }
prepare_for_tools
get_config
collect_log
check_daisy_server

View File

@ -0,0 +1,50 @@
#!/bin/bash
###############################################################################################
# 功能搭建pxe服务器
###############################################################################################
function showhelp
{
echo -e "Usage1: $0 config_file_path"
echo -e "Options:"
echo -e " config_file_path: json file path that contain customized config about pxe server"
echo -e " (json file format is as ${WORKDIR}/json_format/server.json)"
echo ""
echo -e "Usage2: $0 --help display this help and exit"
echo ""
}
# ##############################################################################################
# 入口 #
# ##############################################################################################
WORKDIR=/etc/pxe_install
source $WORKDIR/scripts/common.sh
source $WORKDIR/scripts/interface.sh
#显示帮助提示
if [[ `echo $* |grep -wi 'help'` != "" ]];then
showhelp
exit 0
fi
# 判断入参
if [ ! -f "$1" ]; then
pxelog "[error]json file $1 error...." "console"
exit 1
fi
pxelog "********************begin pxe server install********************" "console"
$WORKDIR/scripts/create_pxesvr.sh ${WORKDIR} $1
pxelog "********************end pxe server install********************\n" "console"
pxelog "************************************************************" "console"
pxelog "good! pxe server been built!" "console"
pxelog "now you can enjoy installing os by pxe server" "console"
pxelog "************************************************************" "console"
exit 0

View File

@ -62,6 +62,8 @@ help:
$(ECHO) ===============================================================================
$(ECHO) make ironicdiscoverdrpm ... generate ironicdiscoverd rpms
$(ECHO) ===============================================================================
$(ECHO) make pxe_server_install ... generate pxe_server_install rpms
$(ECHO) ===============================================================================
$(ECHO) make rpmclean ... clean rpms generated
$(ECHO) ===============================================================================
$(ECHO) make binclean ... clean install.bin generated
@ -97,6 +99,9 @@ ironicdiscoverdrpm:
horizonrpm:
$(MAKE) -C $(_TECS_RPM_PATH)/ horizon
pxe_server_install:
$(MAKE) -C $(_TECS_RPM_PATH)/ pxe_server_install
bin:
$(MAKE) -C $(_TECS_TOOLS_PATH)/setup bin

184
rpm/SPECS/pxe_server_install.spec Executable file
View File

@ -0,0 +1,184 @@
Name: pxe_server_install
License: GPL
Group: Platform Software Department 3 of ZTE Corporation
Version: 1.0.8
Release: %{_release}
Vendor: ZTE Corporation
Summary: Path for pxe server install.
Packager: ZTE-OS
Source: %{name}-%{_release}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{_release}-root
Requires: tar coreutils
BuildArchitectures: noarch
%define _binaries_in_noarch_packages_terminate_build 0
%description
the path indicated for pxe install .
%prep
%setup -q -n %{name}-%{_release}
%install
echo $RPM_BUILD_ROOT
/bin/rm -rf $RPM_BUILD_ROOT
#make install INSTALLROOT="$RPM_BUILD_ROOT" KVER=%{bit_32}
#chmod -R 755 ${RPM_BUILD_ROOT}/etc/pxe_install
mkdir -p $RPM_BUILD_ROOT/usr/bin/
#mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/usrdata/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/json_format/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/nova_compute_mem_moni/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/moni_port/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/interact/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/before/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/ramdisk/
mkdir -p $RPM_BUILD_ROOT/etc/pxe_install/pxe/
#cp -a pxe_install/* $RPM_BUILD_ROOT/etc/pxe_install/
cp pxe_os_install $RPM_BUILD_ROOT/usr/bin/pxe_os_install
cp pxe_os_install_progress $RPM_BUILD_ROOT/usr/bin/pxe_os_install_progress
cp pxe_os_install_clean $RPM_BUILD_ROOT/usr/bin/pxe_os_install_clean
cp pxe_server_install $RPM_BUILD_ROOT/usr/bin/pxe_server_install
cp pxe_server_check $RPM_BUILD_ROOT/usr/bin/pxe_server_check
cp pxe_install/usrdata/readme.txt $RPM_BUILD_ROOT/etc/pxe_install/usrdata/readme.txt
cp pxe_install/json_format/server.json $RPM_BUILD_ROOT/etc/pxe_install/json_format/server.json
cp pxe_install/json_format/os.json $RPM_BUILD_ROOT/etc/pxe_install/json_format/os.json
cp pxe_install/scripts/nic_net_cfg.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/nic_net_cfg.sh
cp pxe_install/scripts/create_pxesvr.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/create_pxesvr.sh
cp pxe_install/scripts/custom/interact.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/interact.sh
cp pxe_install/scripts/custom/after.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after.sh
cp pxe_install/scripts/custom/before.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/before.sh
#cp pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni.py $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni.py
#cp pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni_daemonize.py $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni_daemonize.py
cp pxe_install/scripts/custom/after/address_update.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/address_update.sh
cp pxe_install/scripts/custom/after/create_bond.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/create_bond.sh
cp pxe_install/scripts/custom/after/moni_port/nic_vf_status.c $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/moni_port/nic_vf_status.c
cp pxe_install/scripts/custom/after/moni_port/nic_update $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/moni_port/nic_update
cp pxe_install/scripts/custom/after/moni_port/moni_port_status.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/moni_port/moni_port_status.sh
cp pxe_install/scripts/custom/after/moni_port/moni_port_status $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/moni_port/moni_port_status
cp pxe_install/scripts/custom/after/install_moni_port.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/install_moni_port.sh
cp pxe_install/scripts/custom/after/install_nova_compute_mem_moni.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/after/install_nova_compute_mem_moni.sh
cp pxe_install/scripts/custom/readme.txt $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/readme.txt
cp pxe_install/scripts/custom/interact/neutron_interact.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/interact/neutron_interact.sh
cp pxe_install/scripts/custom/before/create_manager_port_bond.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/before/create_manager_port_bond.sh
cp pxe_install/scripts/custom/custom.conf $RPM_BUILD_ROOT/etc/pxe_install/scripts/custom/custom.conf
cp pxe_install/scripts/interface.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/interface.sh
cp pxe_install/scripts/setup_func.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/setup_func.sh
cp pxe_install/scripts/query_progress.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/query_progress.sh
cp pxe_install/scripts/common.sh $RPM_BUILD_ROOT/etc/pxe_install/scripts/common.sh
cp pxe_install/ramdisk/initrd.img $RPM_BUILD_ROOT/etc/pxe_install/ramdisk/initrd.img
cp pxe_install/ramdisk/vmlinuz $RPM_BUILD_ROOT/etc/pxe_install/ramdisk/vmlinuz
cp pxe_install/pxe/ipxe-roms-qemu-20130517-5.gitc4bce43.el7.noarch.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/ipxe-roms-qemu-20130517-5.gitc4bce43.el7.noarch.rpm
cp pxe_install/pxe/dhcpd.conf $RPM_BUILD_ROOT/etc/pxe_install/pxe/dhcpd.conf
cp pxe_install/pxe/dhcp-common-4.2.5-27.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/dhcp-common-4.2.5-27.el7.x86_64.rpm
cp pxe_install/pxe/xinetd-2.3.15-12.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/xinetd-2.3.15-12.el7.x86_64.rpm
cp pxe_install/pxe/tftp-5.2-11.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/tftp-5.2-11.el7.x86_64.rpm
cp pxe_install/pxe/dhcp-4.2.5-27.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/dhcp-4.2.5-27.el7.x86_64.rpm
cp pxe_install/pxe/default $RPM_BUILD_ROOT/etc/pxe_install/pxe/default
cp pxe_install/pxe/dhcp-libs-4.2.5-27.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/dhcp-libs-4.2.5-27.el7.x86_64.rpm
cp pxe_install/pxe/tftp-server-5.2-11.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/tftp-server-5.2-11.el7.x86_64.rpm
cp pxe_install/pxe/ntpdate-4.2.6p5-18.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/ntpdate-4.2.6p5-18.el7.x86_64.rpm
cp pxe_install/pxe/pxe_kickstart.cfg $RPM_BUILD_ROOT/etc/pxe_install/pxe/pxe_kickstart.cfg
cp pxe_install/pxe/linuxinstall.mount $RPM_BUILD_ROOT/etc/pxe_install/pxe/linuxinstall.mount
cp pxe_install/pxe/tftp $RPM_BUILD_ROOT/etc/pxe_install/pxe/tftp
cp pxe_install/pxe/syslinux-4.05-8.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/syslinux-4.05-8.el7.x86_64.rpm
cp pxe_install/pxe/jq-1.3-2.el7.x86_64.rpm $RPM_BUILD_ROOT/etc/pxe_install/pxe/jq-1.3-2.el7.x86_64.rpm
chmod -R 755 ${RPM_BUILD_ROOT}/etc/pxe_install
chmod +x $RPM_BUILD_ROOT/usr/bin/pxe_os_install
chmod +x $RPM_BUILD_ROOT/usr/bin/pxe_os_install_progress
chmod +x $RPM_BUILD_ROOT/usr/bin/pxe_os_install_clean
chmod +x $RPM_BUILD_ROOT/usr/bin/pxe_server_install
chmod +x $RPM_BUILD_ROOT/usr/bin/pxe_server_check
%files
%defattr(-,root,root)
/usr/bin/pxe_os_install
/usr/bin/pxe_os_install_progress
/usr/bin/pxe_os_install_clean
/usr/bin/pxe_server_install
/usr/bin/pxe_server_check
#/etc/pxe_install/
%doc /etc/pxe_install/usrdata/readme.txt
/etc/pxe_install/scripts/nic_net_cfg.sh
/etc/pxe_install/json_format/server.json
/etc/pxe_install/json_format/os.json
/etc/pxe_install/scripts/create_pxesvr.sh
/etc/pxe_install/scripts/custom/interact.sh
/etc/pxe_install/scripts/custom/after.sh
/etc/pxe_install/scripts/custom/before.sh
#/etc/pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni.py
#/etc/pxe_install/scripts/custom/after/nova_compute_mem_moni/nova_compute_mem_moni_daemonize.py
/etc/pxe_install/scripts/custom/after/address_update.sh
/etc/pxe_install/scripts/custom/after/create_bond.sh
/etc/pxe_install/scripts/custom/after/moni_port/nic_vf_status.c
/etc/pxe_install/scripts/custom/after/moni_port/nic_update
/etc/pxe_install/scripts/custom/after/moni_port/moni_port_status.sh
/etc/pxe_install/scripts/custom/after/moni_port/moni_port_status
/etc/pxe_install/scripts/custom/after/install_moni_port.sh
/etc/pxe_install/scripts/custom/after/install_nova_compute_mem_moni.sh
/etc/pxe_install/scripts/custom/readme.txt
/etc/pxe_install/scripts/custom/interact/neutron_interact.sh
/etc/pxe_install/scripts/custom/before/create_manager_port_bond.sh
/etc/pxe_install/scripts/custom/custom.conf
/etc/pxe_install/scripts/interface.sh
/etc/pxe_install/scripts/setup_func.sh
/etc/pxe_install/scripts/query_progress.sh
/etc/pxe_install/scripts/common.sh
/etc/pxe_install/ramdisk/initrd.img
/etc/pxe_install/ramdisk/vmlinuz
/etc/pxe_install/pxe/ipxe-roms-qemu-20130517-5.gitc4bce43.el7.noarch.rpm
/etc/pxe_install/pxe/dhcpd.conf
/etc/pxe_install/pxe/dhcp-common-4.2.5-27.el7.x86_64.rpm
/etc/pxe_install/pxe/xinetd-2.3.15-12.el7.x86_64.rpm
/etc/pxe_install/pxe/tftp-5.2-11.el7.x86_64.rpm
/etc/pxe_install/pxe/dhcp-4.2.5-27.el7.x86_64.rpm
/etc/pxe_install/pxe/default
/etc/pxe_install/pxe/dhcp-libs-4.2.5-27.el7.x86_64.rpm
/etc/pxe_install/pxe/tftp-server-5.2-11.el7.x86_64.rpm
/etc/pxe_install/pxe/ntpdate-4.2.6p5-18.el7.x86_64.rpm
/etc/pxe_install/pxe/pxe_kickstart.cfg
/etc/pxe_install/pxe/linuxinstall.mount
/etc/pxe_install/pxe/tftp
/etc/pxe_install/pxe/syslinux-4.05-8.el7.x86_64.rpm
/etc/pxe_install/pxe/jq-1.3-2.el7.x86_64.rpm
#%dir %{_prefix}/.channels
%clean
/bin/rm -rf $RPM_BUILD_ROOT
%post
%postun
if [ $1 -eq 0 ];then
/bin/rm -rf /etc/pxe_install
/bin/rm -rf /usr/bin/pxe_os_install
/bin/rm -rf /usr/bin/pxe_os_install_progress
/bin/rm -rf /usr/bin/pxe_server_install
/bin/rm -rf /usr/bin/pxe_os_install_clean
fi
%changelog

View File

@ -17,7 +17,7 @@ rpmforce:
all:clean rpms
rpms:daisy daisyclient ironic-discoverd horizon
rpms:daisy daisyclient ironic-discoverd horizon pxe_server_install
clean:rpmforce
$(RM) $(_TECS_RPM_PATH)/SOURCES/*
@ -65,3 +65,11 @@ horizon:rpmforce
$(RM) $(_TECS_RPM_PATH)/SOURCES/$@-$(_VER_OPENSTACK_REL)
$(RM) $(_TECS_RPM_PATH)/BUILD/$@-$(_VER_OPENSTACK_REL)
pxe_server_install:rpmforce
$(RM) $(_TECS_RPM_PATH)/SOURCES/$@-$(_VER_REL)
$(LN) $(_TECS_CODE_PATH)/$@ $(_TECS_RPM_PATH)/SOURCES/$@-$(_VER_REL)
@cd $(_TECS_RPM_PATH)/SOURCES; $(TARC) $(_TECS_RPM_PATH)/SOURCES/$@-$(_VER_REL).tar.gz --exclude=*.svn \
$@-$(_VER_REL)/*; cd -
$(RPMBUILD) --rmsource $(_TECS_RPM_PATH)/SPECS/$@.spec
$(RM) $(_TECS_RPM_PATH)/SOURCES/$@-$(_VER_REL)
$(RM) $(_TECS_RPM_PATH)/BUILD/$@-$(_VER_REL)

View File

@ -25,8 +25,6 @@ bin: binclean binforce
$(CP) $(_TECS_RPM_PATH)/RPMS/$(PURE_OS_TYPE)/$(ARCH)/* $(_TECS_TOOLS_PATH)/setup/bin_temp
$(RM) $(_TECS_TOOLS_PATH)/setup/bin_temp/*devel*.rpm
$(CP) $(_TECS_CONTRIB_PATH)/rpm/* $(_TECS_TOOLS_PATH)/setup/bin_temp
$(CP) $(_TECS_TOOLS_PATH)/setup/setup.sh $(_TECS_TOOLS_PATH)/setup/bin_temp
$(CP) $(_TECS_TOOLS_PATH)/setup/common/daisy_common_func.sh $(_TECS_TOOLS_PATH)/setup/bin_temp/common