释放双眼,带上耳机,听听看~!
Data:2015/3/29 6:02:27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312 1#!/bin/bash
2#
3echo "Author: Jerrybaby"
4echo "https://github.com/Jerrybaby"
5echo "License: GNU GENERAL PUBLIC LICENSE"
6echo "
7 ------------------------------------------------------------
8 ------------------------------------------------------------
9 ------------------------------------------------------------
10 ------- kickstart 自动化部署服务器端环境安装脚本 -----------
11 ------------------------------------------------------------
12 ------------------------------------------------------------
13 ------------------------------------------------------------
14 "
15
16# environment
17setenforce 0 &> /dev/null
18service iptables stop &> /dev/null
19
20if [ -d "/var/lib/tftpboot" ]
21then
22 rm -rf /var/lib/tftpboot/*
23 rm -rf /tftpboot
24fi
25if [ -f "/var/www/html/files/ks.cfg" ]
26then
27 rm -rf /var/www/html/files/*
28fi
29
30IFACE=`ping -I eth0 -c 4 baidu.com | grep Unreachable | wc -l`
31if [ -z $IFACE ]
32then
33 eth=eth1
34else
35 eth=eth0
36fi
37IPADDR=`ifconfig $eth | grep 'inet addr' | awk -F[:' ']+ '{print $4}'`
38
39download_ubuntu ()
40{
41 echo "Downloading ubuntu-14.04.2-server-amd64......"
42# wget http://119.255.9.54/cdimage.ubuntu.com/releases/14.04.1/release/ ubuntu-14.04.2-server-amd64+mac.iso
43 mount -o loop /root/ubuntu-14.04-server-amd64.iso /mnt
44 echo "OK!"
45}
46
47download_centos ()
48{
49 echo "Downloading centos 6.6-x86_64-minimal......"
50# wget http://mirrors.sohu.com/centos/6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso
51 mount -o loop /root/CentOS-6.5-x86_64-bin-DVD1.iso /mnt
52# mount -o loop /root/CentOS-7.0-1406-x86_64-DVD.iso /mnt
53 echo "OK!"
54}
55
56install_packages ()
57{
58 echo "Installing packages......"
59 yum -y install httpd dhcp tftp-server syslinux
60 echo "OK!"
61}
62
63conf_ubuntu_files ()
64{
65 echo "Configuring ubuntu files......"
66 mkdir -p /var/www/html/files
67 mkdir -p /var/www/html/ubuntu
68 cp -rf /mnt/* /var/www/html/files
69 ln -s /var/lib/tftpboot /tftpboot
70 cp -rf /mnt/install/netboot/* /tftpboot
71 sed -i "s@\(^[[:space:]]append\) vga=788@\1 ks=http://${IPADDR}/files/ks.cfg preseed/url=http://${IPADDR}/files/preseed/ubuntu-server.seed vga=788@g" /tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg
72 echo "d-i live-installer/net-image string http://${IPADDR}/files/install/filesystem.squashfs" | tee -a /var/www/html/files/preseed/ubuntu-server.seed
73 sed -i 's/^timeout 0/timeout 1/g' /tftpboot/ubuntu-installer/amd64/boot-screens/syslinux.cfg
74 echo "d-i mirror/protocol string http" | tee -a /var/www/html/files/preseed/ubuntu-server.seed
75 echo "d-i mirror/http/hostname string cn.archive.ubuntu.com" | tee -a /var/www/html/files/preseed/ubuntu-server.seed
76 echo "d-i mirror/http/directory string /ubuntu" | tee -a /var/www/html/files/preseed/ubuntu-server.seed
77}
78
79conf_centos_files ()
80{
81 echo "Configuring centos files......"
82 mkdir -p /var/www/html/files
83 cp -rf /mnt/* /var/www/html/files
84 ln -s /var/lib/tftpboot /tftpboot
85 mkdir -p /tftpboot/pxelinux.cfg
86 cp /usr/share/syslinux/pxelinux.0 /tftpboot
87 cp /var/www/html/files/images/pxeboot/initrd.img /tftpboot
88 cp /var/www/html/files/images/pxeboot/vmlinuz /tftpboot
89 cp /var/www/html/files/isolinux/*.msg /tftpboot
90 cp /var/www/html/files/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
91 chmod 777 /tftpboot/pxelinux.cfg/default
92 sed -i 's/\(^[[:space:]]disable.*\)yes$/\1no/g' /etc/xinetd.d/tftp
93 sed -i "s/default.*32$/default linux ks=http:\/\/${IPADDR}\/files\/ks.cfg ksdevice=eth0/g" /tftpboot/pxelinux.cfg/default
94 sed -i 's/timeout 600/timeout 1/g' /tftpboot/pxelinux.cfg/default
95 echo "OK!"
96}
97
98dhcp_pro ()
99{
100 echo "配置 DHCP...."
101 (cat | tee /etc/dhcp/dhcpd.conf) << EOF
102ddns-update-style interim;
103ignore client-updates;
104next-server $IPADDR;
105filename "/pxelinux.0";
106subnet 172.16.15.0 netmask 255.255.255.0 {
107 option routers 172.16.15.1;
108 option subnet-mask 255.255.255.0;
109 option domain-name-servers 172.16.254.21, 172.16.254.22;
110 option time-offset -18000;
111 range dynamic-bootp 172.16.15.100 172.16.15.200;
112 default-lease-time 21600;
113 max-lease-time 43200;
114}
115EOF
116 echo "OK!"
117}
118
119ks_cfg__ubuntu ()
120{
121 echo "配置 ks.cfg ...."
122 (cat | tee /var/www/html/files/ks.cfg) << EOF
123#platform=x86, AMD64, or Intel EM64T
124#version=DEVEL
125# Firewall configuration
126firewall --disabled
127# Install OS instead of upgrade
128install
129# Use network installation
130url --url="http://$IPADDR/files"
131# Root password
132#rootpw --plaintext nishishadan
133rootpw --disabled
134user jerry --fullname="jerry" --password nishishadan
135# System authorization information
136auth --useshadow --passalgo=sha512
137# Use text mode install
138text
139# System keyboard
140keyboard us
141# System language
142lang en_US
143# Do not configure the X Window System
144skipx
145# Installation logging level
146logging --level=info
147# Reboot after installation
148reboot
149# System timezone
150timezone Asia/Shanghai
151# Network information
152network --bootproto=dhcp --noipv6
153# System bootloader configuration
154bootloader --location=mbr
155# Clear the Master Boot Record
156zerombr
157# Partition clearing information
158clearpart --all --initlabel
159# Disk partitioning information
160part /boot --fstype="ext4" --size=200
161part / --fstype="ext4" --size=15000
162part swap --fstype="swap" --size=1024
163
164%post --interpreter /bin/bash
165
166apt-get -y install ssh
167
168echo deb http://ppa.launchpad.net/saltstack/salt/ubuntu `lsb_release -sc` main | sudo tee /etc/apt/sources.list.d/saltstack.list
169wget -q -O- "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4759FA960E27C0A6" | sudo apt-key add -
170apt-get update
171apt-get install salt-minion
172echo "master: $IPADDR" >> /etc/salt/minion
173service salt-minion restart
174
175# set the file limit
176ulimit -SHn 65535
177echo "* soft nofile 60000" >> /etc/security/limits.conf
178echo "* hard nofile 65535" >> /etc/security/limits.conf
179
180%end
181EOF
182 echo "OK!"
183}
184
185ks_cfg_centos ()
186{
187 echo "配置 ks.cfg ...."
188 (cat | tee /var/www/html/files/ks.cfg) << EOF
189#platform=x86, AMD64, or Intel EM64T
190#version=DEVEL
191# Firewall configuration
192firewall --disabled
193# Install OS instead of upgrade
194install
195# Use network installation
196url --url="http://$IPADDR/files"
197# Root password
198rootpw --plaintext nishishadan
199# System authorization information
200auth --useshadow --passalgo=sha512
201# Use text mode install
202text
203# System keyboard
204keyboard us
205# System language
206lang en_US
207# SELinux configuration
208selinux --disabled
209# Do not configure the X Window System
210skipx
211# Installation logging level
212logging --level=info
213# Reboot after installation
214reboot
215# System timezone
216timezone Asia/Shanghai
217# Network information
218network --bootproto=dhcp --onboot=on --noipv6
219# System bootloader configuration
220bootloader --location=mbr
221# Clear the Master Boot Record
222zerombr
223# Partition clearing information
224clearpart --all --initlabel
225# Disk partitioning information
226part /boot --fstype="ext4" --size=200
227part / --fstype="ext4" --size=151954
228part swap --fstype="swap" --size=4096
229
230%packages
231@base
232@console-internet
233@core
234@debugging
235@directory-client
236@hardware-monitoring
237@large-systems
238@network-file-system-client
239@performance
240@perl-runtime
241@server-platform
242@server-policy
243@workstation-policy
244pax
245oddjob
246sgpio
247device-mapper-persistent-data
248samba-winbind
249certmonger
250pam_krb5
251krb5-workstation
252perl-DBD-SQLite
253%end
254
255%post --interpreter /bin/bash
256IP=`ifconfig em1 | grep inet | grep -v inet6 | awk -F[' ':]+ '{print $4}'`
257MASK=`ifconfig em1 | grep inet | grep -v inet6 | awk -F[' ':]+ '{print $8}'`
258GATE=`route -n | grep UG | awk '{print $2}'`
259sed -i "s@\(^H.*=\).*@\1server-$IP@g" /etc/sysconfig/network
260sed -i "s@\(^BOOT.*=\).*@\1static@g" /etc/sysconfig/network-scripts/ifcfg-em1
261echo "IPADDR=$IP" >> /etc/sysconfig/network-scripts/ifcfg-em1
262echo "NETMASK=$MASK" >> /etc/sysconfig/network-scripts/ifcfg-em1
263echo "GATEWAY=$GATE" >> /etc/sysconfig/network-scripts/ifcfg-em1
264%end
265EOF
266 echo "OK!"
267}
268
269rest_ser ()
270{
271 echo "重启服务...."
272 umount /mnt
273 service httpd restart
274 service xinetd restart
275 service dhcpd restart
276 chkconfig httpd on
277 chkconfig dhcpd on
278 chkconfig xinetd on
279 chkconfig tftp on
280 echo "OK!"
281}
282
283read -p "本机 IP: $IPADDR,是否正确?Y/N" para
284case $para in
285Y|y)
286 read -p "请选择 Ubuntu(U) 或 CentOS(C)" sys
287 case $sys in
288 U|u)
289 download_ubuntu
290 install_packages
291 conf_ubuntu_files
292 dhcp_pro
293 ks_cfg__ubuntu
294 rest_ser
295 ;;
296 C|c)
297 download_centos
298 install_packages
299 conf_centos_files
300 dhcp_pro
301 ks_cfg_centos
302 rest_ser
303 ;;
304 esac
305 ;;
306N|n)
307 echo "请修改正确的 IP 地址"
308 exit
309 ;;
310esac
311
312