linux下利用脚本搭建无人值守安装服务器
利用脚本实现linux服务器的搭建,可以快速通过网络安装linux系统,下面是自动配置脚本。
[root@helloween ~]# vim /root/桌面/scripts/auto_install.sh
#!/bin/bash
#written by helloween
#=====================================
iptables -F
setenforce 0 >/dev/null 2>&1
#=====================================
#搭建基于ftp的yum源
if rpm -q vsftpd>/dev/null 2>&1 ;then
echo "vsftpd服务已经安装!">/dev/null 2>&1
else
yum install vsftpd -y >/dev/null 2>&1
fi
service vsftpd restart >/dev/null 2>&1
if [ -d /var/ftp/rhel6 ];then
echo "OK">/dev/null 2>&1
else
mkdir /var/ftp/rhel6
fi
mount /dev/cdrom /var/ftp/rhel6 >/dev/null 2>&1
rm -rf /etc/yum.repos.ddhcpd.conf.sample /etc/dhcp/dhcpd.conf
if [ -d /etc/dhcp/dhcpd.conf.bak ];then
echo "原始dhcpd.conf文件备份成功!" >/dev/null 2>&1
else
cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.bak
fi
cp /etc/dhcp/dhcpd.conf.bak /etc/dhcp/dhcpd.conf
echo ‘ddns-update-style none;
subnet 10.0.0.0 netmask 255.255.0.0 {
range 10.0.119.50 10.0.119.100;
option domain-name-servers 10.0.119.1;
option domain-name "sxkj.com";
option routers 10.0.119.1;
default-lease-time 600;
max-lease-time 7200;
filename "pxelinux.0";
next-server 10.0.119.1;
}
‘>>/etc/dhcp/dhcpd.conf
service dhcpd restart >/dev/null 2>&1
#====================================
#搭建无人值守服务器
#yum install system-config-kickstart -y >/dev/null 2>&1
if [ -f /var/ftp/ks.cfg ]; then
echo "ks.cfg文件已存在!">/dev/null 2>&1
else
echo ‘#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="ftp://10.0.119.1/rhel6"
# Root password
rootpw --iscrypted $1$uhLrpOok$/bBDf6drovGhhUjddyp5K1
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang zh_CN
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=1000
part / --fstype="ext4" --grow --size=1
%packages
@base
@basic-desktop
@general-desktop
@input-methods
@legacy-x
@remote-desktop-clients
%end
%post
sed -i ‘$s/3/5‘ /etc/inittab
rm -rf /etc/yum.repos.d/*
wget ftp://10.0.119.1/ftp-yum.repo-O /etc/yum.repos.d/ftp-yum.repo
ipnum=$(ifconfig eth0 | awk -F[.\ ] ‘/Mask/{print$15}‘)
hostname="station$ipnum.wenhao.com"
sed -i s/localhost.localdomain/$hostname/ /etc/sysconfig/network
%end
‘> /var/ftp/ks.cfg
fi
chmod +r /var/ftp/ks.cfg
echo ‘default vesamenu.c32
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to Red Hat Enterprise Linux 6.2!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^AutoInstall rhel6
menu default
kernel vmlinuz
append ks=ftp://10.0.119.1/ks.cfginitrd=initrd.img
label local
menu label Boot from ^local drive
localboot 0xffff initrd=initrd.img
‘ > /var/lib/tftpboot/pxelinux.cfg/default
service vsftpd restart > /dev/null 2>&1
service dhcpd restart > /dev/null 2>&1
servcie xinetd restart > /dev/null 2>&1
chkconfig tftp on
echo "无人值守安装服务器搭建成功!"
exit 0
=======================================================
#使用脚本可以大大较少工作量,做好一个脚本之后,以后的服务器搭建只需稍微修改一下脚本就可以执行安装了。
本文出自 “Helloween” 博客,请务必保留此出处http://6368580.blog.51cto.com/6358580/1398222
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。