如果使用的是原始源,可直接使用该脚本,如果是用的其它源且有cobbler安装包的可删除脚本中的配置yum源步骤。批量部署使用的软件有:cobbler dhcp httpd tftp-server xinetd syslinux pykickstart,其中pykickstart可以不装。
1 #!/bin/bash
2 #检查环境
3 setenforce 0
4 sed -i 's/=enforcing/=disabled/g' /etc/selinux/config
5 systemctl start firewalld
6 systemctl enable firewalld
7 #使用原始源的情况下,增加yum源(原始源无cobbler)
8 YUM=$(ls /etc/yum.repos.d/ |wc -w)
9 if [ "$YUM" -ge 6 ];then
10 echo "
11 [epel]
12 name=epel
13 enabled=1
14 gpgcheck=0
15 baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
16 [centos]
17 name=centos base
18 enabled=1
19 gpgcheck=0
20 baseurl=http://mirrors.163.com/centos/7/os/x86_64/ " > /etc/yum.repos.d/add.repo
21 yum clean all
22 fi
23 #下载所需软件
24 yum -y install cobbler dhcp httpd tftp-server xinetd syslinux pykickstart
25 #配置DHCP
26 IP=`ip a |grep global |awk '{print $2}' |cut -d "/" -f 1`
27 NETM=`ifconfig |grep -w netmask |grep broad |awk '{print $4}'`
28 NETW=`echo $IP |awk -F. '{print $1"."$2"."$3}'`
29 echo "option domain-name \"example.org\";
30 option domain-name-servers ns1.example.org, ns2.example.org;
31 default-lease-time 600;
32 max-lease-time 7200;
33 log-facility local7;
34 subnet $NETW.0 netmask $NETM {
35 range $NETW.10 $NETW.200;
36 option routers $IP;
37 filename \"pxelinux.0\";
38 }" > /etc/dhcp/dhcpd.conf
39 systemctl restart dhcpd
40 systemctl enable dhcpd
41 #配置tftp
42 sed -i '14s/yes/no/g' /etc/xinetd.d/tftp
43 systemctl restart xinetd
44 systemctl enable xinetd
45 #cobbler配置
46 systemctl restart httpd
47 systemctl restart cobblerd
48 systemctl enable httpd cobblerd
49 #cobbler自检
50 cobbler check
51 #修改提示内容
52 sed -i "384s/127.0.0.1/$IP/g" /etc/cobbler/settings
53 sed -i "272s/127.0.0.1/$IP/g" /etc/cobbler/settings
54 systemctl restart rsyncd
55 systemctl enable rsyncd
56 sed -i 101c'default_password_crypted: "$1$0304$1/zFgAR4H1NVwCAgquTcW1"' /etc/cobbler/settings
57 systemctl restart cobblerd
58 cobbler check
59 cobbler sync
60 #挂载光盘
61 mount /dev/cdrom /mnt
62 #生成distro
63 cobbler import --path="/mnt" --name="centos7"
64 cobbler distro list
65 #创建ks文件
66 cp /root/anaconda-ks.cfg /var/lib/cobbler/kickstarts/ks.cfg
67 sed -i 5c"url --url=http://$IP/cobbler/ks_mirror/centos7/" /var/lib/cobbler/kickstarts/ks.cfg
68 #创建profile
69 cobbler profile add --distro="centos7-x86_64" --name="centos7_renren" --kickstart="/var/lib/cobbler/kickstarts/ks.cfg"
70 cobbler profile list
71 #删除不包含kickstart文件
72 cobbler profile remove --name="centos7-x86_64"
73 #添加防火墙
74 firewall-cmd --add-port=67/udp --permanent
75 firewall-cmd --add-port=69/udp --permanent
76 firewall-cmd --add-port=80/tcp --permanent
77 firewall-cmd --add-port=25151/tcp --permanent
78 firewall-cmd --reload