临时PXE安装Linux操作系统

注:为解决远程带宽或光盘挂载安装失败的问题,通过临时PXE环境安装
节点:192.168.0.2

一、安装DHCP

通过dhcp获取ip及boot配置

cat << "EOF" > /etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
ddns-update-style none;
ping-check true;
ping-timeout 3;
default-lease-time 120;
max-lease-time 600;
authoritative;
next-server 192.168.0.2;
filename "undionly.kkpxe";
 
subnet 192.168.0.0 netmask 255.255.255.0 {
    range 192.168.0.200 192.168.0.250;
    option routers 192.168.0.1;
}
EOF
systemctl start dhcpd

二、安装TFTP

/var/lib/tftpboot/menu.c32
/var/lib/tftpboot/undionly.kkpxe


cat << "EOF" > /var/lib/tftpboot/pxelinux.cfg/default 
DEFAULT centos7.4
LABEL centos7.4
KERNEL http://192.168.0.2/www/os/centos/7.4/images/pxeboot/vmlinuz
APPEND initrd=http://192.168.0.2/www/os/centos/7.4/images/pxeboot/initrd.img ksdevice=bootif ks=http://192.168.0.2/www/kickstarts/default selinux=0 biosdevname=1 net.ifnames=0 rhgb quiet console=tty0 ixgbe.allow_unsupported_sfp=1 
IPAPPEND 2
EOF


systemctl start tftp

三、安装HTTP

提供安装镜像

cat << "EOF" > /data/nginx/conf.d/nginx.conf 
server
{
    listen 80;
    server_name 192.168.0.2;

    location /www {
        root   /data/nginx/;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

    access_log /data/nginx/logs/access.log;
    error_log /data/nginx/logs/error.log;
}

systemctl start openresty
# 挂载镜像并拷贝至相应目录
[root@gk-hpc-10-11-14-6 ~]# ls -l /data/nginx/www/os/centos/7.4/
total 308
-rw-rw-r-- 1 root root     14 Sep  5  2017 CentOS_BuildTag
drwxr-xr-x 3 root root     35 Sep  5  2017 EFI
-rw-rw-r-- 1 root root    227 Aug 30  2017 EULA
-rw-rw-r-- 1 root root  18009 Dec 10  2015 GPL
drwxr-xr-x 3 root root     57 Sep  5  2017 images
drwxr-xr-x 2 root root    198 Sep  5  2017 isolinux
drwxr-xr-x 2 root root     43 Sep  5  2017 LiveOS
drwxrwxr-x 2 root root 217088 Sep  5  2017 Packages
drwxr-xr-x 2 root root   4096 Sep  5  2017 repodata
-rw-rw-r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root   2883 Sep  6  2017 TRANS.TBL
# 创建临时kickstart文件


cat << "EOF" > /data/nginx/www/kickstarts/default
auth --enableshadow --passalgo=sha512 #指定shadow文件验证,sha512算法
url --url="http://192.168.0.2/www/os/centos/7.4" #指定安装地址
repo --name="AppStream" --baseurl="http://192.168.0.2/www/os/centos/7.4" #指定安装地址
text
firewall --disable #关闭防火墙
firstboot --disable #安装后第一次启动默动
selinux --disabled #关闭Selinux
keyboard --vckeymap=us --xlayouts='us' #指定使用美式键盘
lang en_US.UTF-8 #指定字符集
reboot
rootpw --iscrypted xxxxxxxxxxx
skipx #跳过图形界面
services --enabled="chronyd"
timezone Asia/Shanghai #指定时区
install
clearpart --all --initlabel --drives=sda #清空sda磁盘分区

%include /tmp/part-include
%pre --interpreter=/bin/sh
disk=$(cat /proc/partitions | grep -vE "name|[0-9]$|^$" |awk '$3>=20971520{print$0}'|sort -nk3|head -n 1|awk '{print$NF}')
disk_size=$(cat /proc/partitions | grep -vE "name|[0-9]$|^$" |awk '$3>=20971520{print$0}'|sort -nk3|head -n 1|awk '{print$3}')

cat > /tmp/part-include << EOF
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=$disk #指定引导程序的位置,默认为mbr 
part biosboot  --fstype=biosboot --ondisk=$disk --size=1
#part swap --fstype="swap" --ondisk=$disk --size=16384 #设置swap分区
part /boot --fstype="xfs" --ondisk=$disk --size=1024 #设置引导分区
EOF

cat >> /tmp/part-include << EOF
part / --fstype="xfs" --grow --ondisk=$disk --size=10240 #剩余磁盘分配给/
EOF
%end

%packages
@^minimal
@core
@network-tools
@compat-libraries
kexec-tools
net-tools
ipmitool
pciutils
dos2unix
ntpdate
sysstat
telnet
parted
iotop
rsync
lrzsz
unzip
bzip2
perf
nmap
wget
gcc
vim
wireshark
#base
libtool-ltdl
nfs-utils
psmisc
bash-completion
tree
policycoreutils-python
#python2-pip
python-backports                    
python-backports-ssl_match_hostname 
python-ipaddress                    
python-setuptools
#ipvs
ipvsadm
ipset
ipset-libs
#fastlinq 8.53.0.3
elfutils-libelf-devel
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'
%end

%post

if /usr/sbin/lspci|grep "FastLinQ QL41000" &> /dev/null;then
  wget -P /root/initial/ http://www.example.com/www/upload/fastlinq-8.55.6.3.tgz
  tar -zxf /root/initial/fastlinq-8.55.6.3.tgz -C /root/initial/
cat << "EOF" >>/etc/rc.d/rc.local
cd /root/initial/fastlinq-8.55.6.3&&make KVER=4.19.12-1.el7.elrepo.x86_64 install&&sed -i "/fastlinq/d" /etc/rc.d/rc.local #reboot
EOF
fi

# custom bash prompt
cat <<EOF > /etc/sysctl.conf
vm.swappiness=0
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
vm.dirty_background_ratio=5
vm.dirty_ratio =60
net.ipv4.tcp_mem = 3097431 4129911 6194862
net.ipv4.tcp_rmem = 4096 87380 6291456
net.ipv4.tcp_wmem = 4096 65536 4194304
net.core.wmem_default = 131072
net.core.rmem_default = 131072
net.core.wmem_max = 2097152
net.core.rmem_max = 2097152
net.ipv4.tcp_max_tw_buckets = 262144
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_tw_recycle = 0   
net.ipv4.tcp_tw_reuse  = 1     
net.ipv4.tcp_syncookies  = 1        
net.ipv4.tcp_fin_timeout = 15      
net.ipv4.tcp_timestamps = 1      
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_syn_backlog = 65535  
net.core.somaxconn  = 65535      
net.core.netdev_max_backlog  = 200000
EOF

cat > /etc/security/limits.d/90-nproc.conf << EOF
root   soft   nproc   unlimited
EOF

cat > /etc/security/limits.d/nproc-nofile.conf << EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF

grep ^ulimit /etc/rc.local &> /dev/null||echo "ulimit -HSn 65535" >> /etc/rc.local

cat >> /etc/profile <<'EOF'
export LANG=en_US.UTF8
export PS1="[\[\e[32;1m\]\u@\[\e[33;1m\]$ip\h \[\e[32;0m\]\w]\\$ "
export HISTTIMEFORMAT='[%F %T]# '
export HISTFILESIZE=5000
EOF

# config service
service=(crond network ntpd rsyslog sshd sysstat yum-updatesd)
chkconfig --list | awk '{ print $1 }' | xargs -n1 -I@ chkconfig @ off
echo ${service[@]} | xargs -n1 | xargs -I@ chkconfig @ on
rm -f /usr/lib/systemd/system/ctrl-alt-del.target
sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
sed -i 's/\(^SELINUX=\).*$/\1disabled/' /etc/selinux/config
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
#光模块配置
sed -i "/CMDLINE/ s/\"$/ ixgbe.allow_unsupported_sfp=1\"/g" /etc/default/grub 
rpm -ivh  http://www.example.com/www/packages/network/ixgbe-5.6.3-1.x86_64.rpm
grub2-mkconfig -o /boot/grub2/grub.cfg
echo "options ixgbe allow_unsupported_sfp=1" > /etc/modprobe.d/ixgbe.conf
dracut --regenerate-all --force
systemctl disable NetworkManager

#绑定网卡及Mac地址
ifconfig | egrep -v "^lo:|^bond" | grep mtu|awk -F ":" '{print$1}' | while read i;do echo "ACTION==\"add\", SUBSYSTEM==\"net\", DRIVERS==\"?*\", ATTR{type}==\"1\", ATTR{address}==\"$(ifconfig $i | grep " ether "|awk '{print$2}')\", NAME=\"$i\"" >> /usr/lib/udev/rules.d/60-net.rules;done
# config network
reboot
%end
EOF
  • 12
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值