bash -n test.bash #查看bash是否存在语法错误
bash -x test.bash #查看bash详细的执行过程
#!/bin/bash
#系统环境准备
ip link set dev ens37 up
ip addr add 10.100.10.1/24 dev ens37
systemctl restart network
#安装DHCP
dhcp_conf="/etc/dhcp/dhcpd.conf" #dhcp配置文件
yum -y install dhcp
mv ${dhcp_conf} d h c p c o n f b a c k u p c a t > {dhcp_conf}_backup cat> dhcpconfbackupcat>{dhcp_conf}<<EOF
subnet 10.100.10.0 netmask 255.255.255.0 {
range 10.100.10.10 10.100.10.254; #可分配的起始IP-结束IP
option subnet-mask 255.255.255.0; #设定netmask
default-lease-time 21600; #设置默认的IP租用期限
max-lease-time 43200; #设置最大的IP租用期限
next-server 10.100.10.1; #告知客户端TFTP服务器的ip
filename “/pxelinux.0”; #告知客户端从TFTP根目录下载pxelinux.0文件
#option domain-name-servers www.baidu.com;
#option domain-name “10.100.10.1”;
#option routers 10.100.10.1;
#option broadcast-address 10.100.10.255;
}
EOF
#DHCP指定监听网卡
dhcpd_service_old="/usr/lib/systemd/system/dhcpd.service" #原dhcp服务文件
dhcpd_service="/etc/systemd/system/dhcpd.service" #dhcp服务文件
cp ${dhcpd_service_old} ${dhcpd_service}
sed -i ‘s/dhcpd --no-pid/dhcpd --no-pid ens37/g’ ${dhcpd_service} #指定监听网卡
#sed -i ‘/dhcpd --no-pid/a\ens37’ #在下一行添加
systemctl --system daemon-reload
systemctl restart dhcpd.service
#安装TFTP服务
tftp_conf="/etc/xinetd.d/tftp" #tftp配置文件
yum -y install xinetd tftp-server
cp ${tftp_conf} ${tftp_conf}_backup
sed -i ‘s/disable = yes/disable = no/g’ ${tftp_conf} #将disable改为no
systemctl restart xinetd
systemctl restart tftp.socket
systemctl restart tftp.service
#配置HTTP服务
http_default_dir="/var/www/html" #http默认发布目录
http_dir="${http_default_dir}/centos-7" #http发布目录
yum -y install httpd
cd /etc/httpd/conf.d/
mv welcome.conf welcome.conf_backup