shell——一鍵部署服務實戰

l文峰發表於2020-11-18

DNS服務的一鍵化部署

#!/bin/bash
#dns服務一鍵化部署
dns=/var/named
dns_conf=/etc/named.conf
dns_zones=/etc/named.rfc1912.zones
local=/var/named/lcx.com.local
zone=/var/named/lcx.com.zone

yum -y install bind*

sed -i '/port/s/{.*}/{ 20.0.0.11; }/' $dns_conf
sed -i '/allow-query/s/{.*}/{ any; }/' $dns_conf
grep -w "20.0.0.11" $dns_zones || cat /root/named_zones.txt >> $dns_zones
sed -i 's/\r$//' $dns_zones

cp -p $dns/named.localhost $dns/lcx.com.local
cp -p $dns/named.loopback $dns/lcx.com.zone
chown root:named lcx.com.zone
chown root:named lcx.com.local

cat /root/local.txt > $local
cat /root/zone.txt > $zone

grep -w "20.0.0.11" /etc/resolv.conf || sed -i '1inameserver 20.0.0.11' /etc/resolv.conf

systemctl restart named.service
systemctl status named.service
systemctl restart httpd
systemctl status httpd

nslookup www.lcx.com

以下幾個配置檔案均放在/root下

vim local.txt #(文字名)
$TTL 1D
@       IN SOA  aa.com.  rname.invalid. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      lcx.com. #注意點
        A       20.0.0.11 #(DNS伺服器地址)
10 IN PTR      www.aa.com. #注意點
11 IN PTR      ftp.aa.com. #注意點
vim named_zones.txt #(文字名)
zone "lcx.com" IN {
        type master;
        file "lcx.com.zone";
        allow-transfer { 20.0.0.11; };
        also-notify { 20.0.0.11; };
};
zone "0.0.20.in-addr.arpa" IN {
        type master;
        file "lcx.com.local";
        allow-transfer { 20.0.0.11; };
};
vim zone.txt
$TTL 1D
@       IN SOA  @ rname.invalid.  (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      @
        A        20.0.0.11 #(DNS伺服器地址)
www  IN A     20.0.0.11 #(DNS伺服器地址)
ftp  IN A       20.0.0.11 #(DNS客戶機地址)
mail IN CNAME   www

NFS服務的一鍵化部署

#!/bin/bash
#一鍵部署NFS服務
html=/opt/web/index.html
nfs=/etc/exports

yum -y install nfs*
yum -y install rpcbind

chkconfig --level 35 nfs on  # chkconfig工具管理nfs服務
chkconfig --level 35 rpcbind on # chkconfig工具管理rpcbind服務

[ -e /opt/web ] || mkdir /opt/web

cat /root/index.html.txt > $html
cat /root/exports.txt > $nfs

service rpcbind restart
service nfs restart
showmount -e
systemctl status rpcbind
systemctl status nfs

以下幾個配置檔案均放在/root下

vim exports.txt #(文字名)
/opt/web 20.0.0.12(ro)
vim index.html.txt #(文字名)
<html><title>web</title><body><h1>this is the web!!!</h1></body></html>

PXE服務的一鍵化部署

#!/bin/bash
#一鍵部署pxe服務
tftp=/etc/xinetd.d/tftp
tftpboot=/var/lib/tftpboot
tftp_default=/var/lib/tftpboot/pxelinux.cfg/default
dhcp=/etc/dhcp/dhcpd.conf
vsftpd=/var/ftp/pub

yum -y install tftp*
sed -i '/disable/s/yes/no/g' $tftp

yum -y install dhcp
cat /root/dhcp_conf.txt >> $dhcp

yum -y install vsftpd
mount /dev/cdrom $vsftpd

yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 $tftpboot
[ -e $tftpboot/pxelinux.cfg ] || mkdir $tftpboot/pxelinux.cfg
cp /mnt/isolinux/isolinux.cfg $tftp_default
cp /mnt/images/pxeboot/initrd.img $tftpboot
cp /mnt/images/pxeboot/vmlinuz $tftpboot
cp  /mnt/isolinux/vesamenu.c32 $tftpboot

yum -y install system-config-kickstart
sed -i 'd' $tftp_default
cat /root/tftp_default.txt >> $tftp_default
cat /root/ks.cfg.txt >> /var/ftp/ks.cfg

service dhcpd restart
service vsftpd restart

yum -y install xinetd
service xinetd start
chkconfig --level 35 xinetd on
chkconfig --level 35 tftp on

systemctl status dhcpd
systemctl status vsftpd
systemctl status xinetd

以下幾個配置檔案均放在/root下

vim dhcp_conf.txt #(文字名)
ddns-update-style none;
next-server 20.0.0.11;
filename "/pxelinux.0";
subnet 20.0.0.0 netmask 255.255.255.0 {
  range  20.0.0.15 20.0.0.150;
  option routers 20.0.0.11;
  option domain-name-servers 8.8.8.8, 114.114.114.114;
}
vim ks.cfg.txt #(文字名)
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$wwYHSvul$A16RzS3Pl5LCCz.myTIdR0
# Use network installation
url --url="ftp://192.168.100.130/pub"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /home --fstype="xfs" --size=5000
part swap --fstype="xfs" --size=5000
part / --fstype="xfs" --grow --size=1

%post --interpreter=/bin/bash
cd /etc/yum.repos.d
rm -f *
echo -e "[base]" >> auto.repo
echo -e "name=yum" >> auto.repo
echo -e "baseurl=ftp://20.0.0.13/pub" >> auto.repo
echo -e 'gpgcheck=0" >> auto.repo
echo -e "enable=1" >> auto.repo
%end

%packages
@^gnome-desktop-environment
@backup-client
@base
@compat-libraries
@core
@desktop-debugging
@development
@dial-up
@directory-client
@fonts
@gnome-apps
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-applications
@internet-browser
@java-platform
@legacy-x
@multimedia
@network-file-system-client
@networkmanager-submodules
@office-suite
@print-client
@security-tools
@smart-card
@x11
kexec-tools

%end

vim tftp_default.txt #(文字名)
default auto
prompt 0
label auto
     kernel vmlinuz
     append initrd=initrd.img method=ftp://20.0.0.11/pub ks=ftp://20.0.0.11/ks.cfg
label linux text
     kernel vmlinuz
     append text initrd=initrd.img method=ftp://20.0.0.11/pub
label linux rescue
     kernel vmlinuz
     append rescue initrd=initrd.img method=ftp://20.0.0.11/pub

相關文章