CentOS自动化安装实战

2020-01-30 14:40:57王振洲

firewall --disabled
install
cdrom
rootpw --iscrypted $1$stMs72eG$G3f0zhGBjp6/SioZ28CxQ0
auth --useshadow --passalgo=md5
text
firstboot --disable
keyboard us
lang en_US.UTF-8
selinux --disabled
# Do not configure the X Window System
skipx
logging --level=info
reboot --eject
timezone Asia/Shanghai
network --device em1 --bootproto=static --ip=192.168.7.123 --netmask=255.255.248.0 --gateway=192.1s
bootloader --location=mbr --driveorder=sda

# Clear the Master Boot Record
zerombr yes

# Partition clearing information
clearpart --all --initlabel

# Disk partitioning information
part / --fstype="ext4" --size=10240
part swap --size=4096
part /data --fstype="ext4" --grow --size=1

%packages
@base
@core
@server-policy
sgpio
device-mapper-persistent-data
ntp

%post --nochroot
mkdir -p /mnt/sysimage/tmp/custom_data >> /tmp/custom.log 2>&1
cp /mnt/source/Packages/lnmp_pack.tar.gz /mnt/sysimage/tmp/custom_data >> /tmp/custom.log 2>&1
cp /mnt/source/Packages/install_packages.sh /mnt/sysimage/tmp/custom_data >> /tmp/custom.log 2>&1
cp /mnt/source/Packages/ncftp-3.2.5-src.tar.gz /mnt/sysimage/tmp/custom_data >>/tmp/custom.log 2>&1
cp /mnt/source/Packages/rarlinux-3.8.0.tar.gz /mnt/sysimage/tmp/custom_data >>/tmp/custom.log 2>&1
cp /mnt/source/Packages/nmon_linux_14i.tar.gz /mnt/sysimage/tmp/custom_data >>/tmp/custom.log 2>&1

%post
cd /tmp/custom_data >> /tmp/custom.log 2>&1
chmod +x install_packages.sh
sh install_packages.sh

# remove custom_data
rm -rf /tmp/custom_data

#vim syntax on
echo alias vi='vim' >> /etc/bashrc

# disable ipv6
echo "alias net-pf-10 off" >> /etc/modprobe.d/dist.conf
echo -e "optionstipv6tdisable=1" >> /etc/modprobe.d/dist.conf
echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network

#append lib
echo "/usr/local/lib/" >> /etc/ld.so.conf

#modify lang
echo 'export LANG=zh_CN.UTF8' >> /etc/profile

#disable system auto mail
echo "unset MAILCHECK" >> /etc/profile

#modify history
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
sed -i "s/HISTSIZE=1000/HISTSIZE=999999999/" /etc/profile

#modifu ssh port on 3389
echo 'Port 3389' >> /etc/ssh/sshd_config
echo 'UseDNS no' >> /etc/ssh/sshd_config

for i in `ls /etc/rc3.d/S*`
do
CURSRV=`echo $i|cut -c 15-`
chkconfig --level 3 $CURSRV off
done

for i in crond rsyslog iptables network ntpd sshd sysstat;do chkconfig --level 3 $i on;done

sed -i '/HOSTNAME=/d' /etc/sysconfig/network
echo 'HOSTNAME=test' >> /etc/sysconfig/network

# sysctl
echo "net.core.netdev_max_backlog = 32768" >> /etc/sysctl.conf