RHEL下一键部署服务脚本(GUI界面)

重磅更新:增加图形化界面!!!,优化了代码,提高效率,采用并发式执行。
功能如下:
1.配置yum源
2.配置ip地址
3.配置nfs客户端
4配置DHCP服务
5.配置DNS服务
6.搭建PXE+Kickstart无人值守安装服务
部分运行截图:
在这里插入图片描述
在这里插入图片描述

#部分代码如下
#Author:roya
#DESCIRPTION:One click deployment of CentOS service
#SCRIPET NAME:RONE_DEPLOY
#CREATE TIME:2020-01-23
#UPDATE TIME:2020-02-04
#VERSION:0.30
#!/bin/bash
OPTION=$(whiptail --title "Menu Dialog" --menu "Please select the service you want to configure: " 15 60 6 \
"1" "Configure Yum source" \
"2" "Configure IP address" \
"3" "Configure NFS server" \
"4" "Configure DHCP server" \
"5" "Configure DNS server" \
"6" "Configure PXE unattended installation service" 3>&1 1>&2 2>&3)
case $OPTION in
1)
if [!-e /media/cdrom]
then sleep 0.1 
else mkdir /media/cdrom
fi
function Yum()
{
echo "/dev/cdrom /media/cdrom iso9660 defaults 0 0" >> /etc/fstab 
mount -a &> /dev/null 
echo '[rhel]
name=rhel
baserl=file:///media/cdrom
gpgcheck=0
enable=1' > /etc/yum.repos.d/rhel.repo
}
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.1
echo $i
done 
} | whiptail --gauge "Configuring, please wait..." 6 60 0 &
Yum &
wait
yum update &> /dev/null
if [ $? -eq 0 ] 
then  
whiptail --title "Message Box" --msgbox "Yum Source Configuration Successed!" 10 40
else 
whiptail --title "Message Box" --msgbox "Yum source Configuration Failed!" 10 40
fi
;;
2)
function IPConfigure()
{
IPADDR=`ifconfig | awk -F ' ' 'NR==2{print$2}'`
NETCARD=$(whiptail --title "Net Card" --inputbox "Please enter the network card name: " 10 60 ens33 3>&1 1>&2 2>&3)
IPADDRES=$(wtail --title "IP Address" --inputbox "Please enter IP Addres: " 10 60 192.168.1.1/24 3>&1 1>&2 2>&3) 
nmcli connection mody $NETCARD ipv4.addresses $IPADDRESS
nmcli connecion modify $NETCARD ipv4.method manual
GATEWAY=$(whiptil --title "GateWay" --inputbox "Please enter GATEWAY: " 10 60 192.168.1.254 3>&1 1>&2 2>&3)
DNS=$(whiptail --title "DNS server" --inputbox "Please enter DNS server: " 10 60 114.114.114.114 3>&1 1>&2 2>&3)
nmcli connecion mdify $NETCARD ip4.dns $DNS ipv4.gateway $GATEWAY &> /dev/null
nmcli connection modify $NETCARD connection.autoconnect yes &> /dev/null
}
IPConfigure 
{
for ((i = 0 ; i <= 100 ; i+=5))
do 
sleep 0.1 
echo $i
done 
} | whiptail --auge "Configuring, please wait..." 6 60 0 
systemctl restox "Your IP address is $IPADDR" 10 40
else 
whiptail --tile "Message Box" --msgbox "Network Configration Failed!" 10 40
fi
;;
3)
function nfs()
{
yum install -y nfs-ils &> /dev/null &
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.1
echo $i
done 
} | whiptail --gauge "Configuring, please wait..." 6 60 0 &
wait
IPADDRS=`ifconfig | awk -F ' ' 'NR==2{print$2}'`
NFSSD=$(whiptail --title "NFS Share Directory" --inputbox "Please enter NFS directory path you want to share: " 10 70 /nfsdir 3>&1 1>&2 2>&3)
NFSSI=$(whptail 
NFSSHP=$(whiptail --title "e shared host: " 10 60 sync,rw,all_squash 3>&1 1>&2 2>&3)
}
nfs
if [ ! -e $NFSSD ]
then  
mkdir $NFSSD &> /dev/null
chmod -Rf 777 $NFSSD 
fi
cat > /etc/exports << EOF
$NFSSD $NFSSI($NFSSHP)
EOF
exportfs -r &> /dev/null
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.1
echo $i
done 
} | whiptail --gauge "Configuring, please wait..." 6 60 0 
function nfsfirewalld()
{
systemctl restart rpcbind  
systemctl enabee rpcbind &> /dev/null
systemctl enable nfs-s
systemctl restart nfs-sevrer && systemctl enable nfs-server &> /dev/null
nfsfirew
whiptail --title "Message Box" --msgbox "NFS Service Configuration Failed!" 10 40 
fi
;;
4)
yum install -y dhcp &> /dev/null &
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.2
echo $i
done 
} | whiptai --gauge "Installing, please wait..." 6 60 0 &
wait
OPTION1=$(whiptail --title "DNS Services Dynamic Update" --menu "Please enter the type of DNS service dynamic update: " 10 30 3 \
"none" "1" 
"allow" "2"  3>&1 1>&2 2>&3)
DOMAIN=$(whiptail --title "DNS Domain" --inpudbox "Please enter a DNS domain : " 10 40 runtime.com 3>&1 1>&2 2>&3)
IP=`ifcofig | awk -
IP1="expr`ifconfig| awk -F ' ' 'NR==2{print$2}'  | awk -F '.' '{pri$4} + 20" 
IP3="echo "`ifconfig | awk -F ' ' 'NR==2{print$2}' | cut -d '.' -f 1,2,3`.`$IP1`"" 
IP4="echo `ifconfig | awk -F ' ' 'NR==2{print$2}' | cut -d '.' -f 1,2,3`.`$IP2`""
cat > /etc/dhcp/dhcpd.conf << EOF
ddns-NTMASK;
option routers $IP;
option doma0;
max-lease-time 43200;
}
EOF
systemctl restart dhcpd > /dev/null &
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.1
echo $i
done 
} | whiptail --gauge "Configuring, please wait..." 6 60 0 &
wait
STATUS=$(stemctl tatuhcpd | grep Active | cut -d ':' -f 2 | awk -F ' ' '{print$1}')
if [ "$STATUS" == "active" ]
then 
firewall-cmd --panent --add-service=dhcp  &> /dev/null
firewall-cmd --reloa &> /dev/null
else 
whiptail --title "Message Box" --msgbox "DHCP Service Configuration Failed" 10 40
fi
;;
5)
yum install -y bind* &> /dev/null &
{
for ((i = 0 ; i <=100 ; i+=5))
do
sleep 0.2
echo $i
done w-query     { any; };/g" /etc/named.conf
domain=$(whipail --title "DOMAIN" --inputbox "Please enter the domain name to be resoved:  10 70 runtime.com 3>&1 1>&2 2>&3)
IP_0="`ifconfig | awk -F ' ' 'NR==2{print$2}'`"
IP_1="`ifconfig| 
cat > /etc/named.rfc1912.zones << EOF
zone "$domain" IN {
        type master;
        file "$domain.local";
        allow-update { none; };
};
zone "$IP_3.$IP_2.$_1.in-addr.arpa" IN {
        type master;
        file "$doin.zone";
        allow-update { none; };
};
EOF
cp -a /var/named/named.localhost /var/named/$domain.local
cp -a /var/name/ned.loopback /var/named/$domain.zone
cat > /var/named/$din.lcal << EOF
\$TTL 1D   ; minimum
        NS      ns.$domain.
ns      A       $IP_0
        A       $IP_0
EOF
cat > /var/named/$domain.zone << EOF
\$TTL 1D
@       IN SOA  root.$domain. $domain. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS        ns.$domain.
$IP_4   PTR       $domain.
$IP_4   PTR       ns.$domain.      
EOF
}
dns &
systemctl re
echo $i
done 
} | whiptail --gauge "Configuring, please wait..." 6 60 0 &
wait
if [ "$status" == 'active' ]
then 
;;
6)
function installed()
{/null
yum install -y vsft &> /dev/null
}
installed &
{
for ((i = 0 ; i <=100 ; i+=2))
do
sleep 1
echo $i
done
} | whiptail --gauge "Installing, please wait..." 6 60 0 &
wait
IP_a=`ifconfig | awk -F ' ' 'NR==2{print$2}'`
netmak=`ifconfig | ==2{print$2}'  | awk -F '.' '{print$4}'` + 100 P_e="expr `ifconfig| awk -F ' ' 'NR==2{print$2}'  | awk -F '' '{print$4}'` + 200
IP_g="echo "`ifconfig | awk -F ' ' 'NR==2{print$2}' | cut -d '.' -f 1,2,3`.`$IP_e`""
function Configured()
{
cat > /etc/dhcp/dhcpd.conf << EOF
allow booting;
allow botp;   $netmask;
        option do-bootp `$IP_f` `$IP_g`;
        defa-lese-time          43200;
        next-server             $IP_a;
        filename                "pxelinux.0";
}
EOF
systemctl restart dhcpd 
if [ $? -eq 0 ]
then 
exit 0
fi
cat > /etc/xinetd.d/tftp <<EOF
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wa                    = yes
        usr                    = root
        srver_args             = -s /var/lib/tftpboot
        disable                 = no
        per_surce              = 11
        cps                     = 100 2
        fl   
if [ $? -eq 0 ] 
then
whiptai--title"Message Box" --msgbox "TFTP Servcie Configuration Successe!" 10 50 
else 
cp /ur/share/liu/iags/pxeboot/mlinuz,initrd.img} /var/lib/tftpboot
cp /mediacdrom/isli{vesamenu.c32,boot.msg} /var/lib/tftpboot
if [ ! -e /var/lib//ppb
cp /media/cdrom/isolnux/isolinux.cfg /var/lib/tftpboot/pxec/redhat-release | awk -F ' ' '{print$7}'`
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
default lin
# For vesamenux $version_0
menu vshift 8
menu rows 18
menu magrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected i
menu color hotsel 0 #84b8ffff #00000000 none
# Unselectedffff #ff355594 none
# Timeout msg #fffffff #00000000 none
menu color tieout_
menu separator  insert an empty line
label linuxRed Hat Enterprise Linux $version_0
  kernel vmlinuzg inst.stage2=ftp://$IP_a ks=ftp://$IP_a/pub/ks.cfg quiet
label chec
  menu label Test this ^media & install Red Hat Enterprise Linux $version_0
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.6\x20Server.x86_64 rd.live.check quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshoo
  text help
label rescue
  menu indent count 5
  menu label ^Rescue a Red Hat Enterprise Linux system
  text help
	If the system will not b t try to get it booting again.
  endtextinuz
  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-$version_0\x20Server.x86_64 rescue quiet
label memtest
  menu label Run a ^memory test
  text help
	If your system is having issues, a problem with your
	system's memory may be the cause. Use this utility to
	see if the memory is working correctly.
  endtext
  kernel memtest
menu separator # insert an empty line
label local
  menu label Boot from ^local drive
  localboot 0xffff
menu separato # insert an empty line
menu separator# insert an empty line
label returntoturn to ^main menu
  menu exit
EOF
systemctl restart vsftpd 
if [ $? 
whiptail --10 50
else le "Message Box" --msgbox "FTP Service Configuration Successed!" 10 5
fi
systemctl enable vsftpd &> /dev/null
firewall-cmd --permanent --add-service=ftp &> /dev/null
firewall-cmd --reload &> /dev/null
setsebool -P ftpd_connect_all_unreserved=on &> /dev/null
cp ~/anaconda-ks.cfg /var/ftp/pub/ks.cfg
chmod +r /var/ftp/pub/ks.cfg
echo "#version=RHEL$version_0
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Sver-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Sever-ResilientStorage" --baseurl=file:///aIP_a
# Use graphicalinstall
graphical
# Run the Setup Agt on first boot
firstboot -enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhc-device=ens33 --ipv6=auto --no-activate
network  --hostname=localhost.localdomain

# Root password
rootpw --iscrypted \$6\$qRAoZkxh5SHa7N4X\$w2osf.ZFey1hPtFdOJVIMgVOzc8dygUol2JphmSNQB6MHb7vPL63D6s9hIfrT9ydduKFOlq0S5/kp6.zJzYMy.
# System services ervices --enabled=
timezone Asia/Shanghai --isUtc
user -name=r\$ZT/uZLv5GPvdSNr7\$caWMweAE4l9z93nmeRSttpiwHeJr9rjEGlAANrZBv5pRcZVkUfFzTAow System configuration information
xconfig  --tartxonboot
# Systm bootloader configuration
bootloader --location=mbr--boot-drive=sda
# Partition clearing informabel
# Disk partitioning information
part swap --fstype="swap" --ondisk=sda --size=5000
part / --fstype="xfs" --ondisk=sda --size=13000

%packages
@^graphical-server-environment
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnomedesktop
@gues-agents
@guet-desktop-agents
@harareonitoring
@input-methods
@iteret-browser
@multimeint-client
@x
chrony

%end
" > /var/f
Configured &rom/* /var/ftp &
{
for ((i = 0 ; i <=100 ; i+=1))
do
sleeo $i           
done 
} t
whiptail --title "Message Box" --msgbox "PXE Service Configuration Succes                                                          
exit
esac

写作不易,还望支持,大家的评论和点赞将是我最大动力,感谢支持!,感兴趣的快来私信笔者吧

发布了36 篇原创文章 · 获赞 83 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/gd_9988/article/details/104173929