一键部署dns服务_RHEL7(Centos7)下使用shell脚本一键部署服务(二)

新增了一键配置DHCP服务功能,后续准备添加配置DNS服务的功能

#author:Roya#script name:RyndOne-deploy#creation time:2020-01-23#version:0.1#update time:2020-01-24#!/bin/bashecho "input 1:Configure Yum source"echo "input 2:Configure IP address,gateway,subnet mask,DNS server"echo "input 3:Configure NFS server"echo "input 4:Configure DHCP server" echo "input 5:Configure DNS server"read -p "please input 1,2,3,4: " a case $a in #使用case语句判断输入1)echo "Prepare to configure Yum source...."sleep 1  #等一秒执行下面命令echo "One moment please"sleep 3echo "/dev/cdrom /mnt iso9660 defaults 0 0" >> /etc/fstab && mount -a &> /dev/null && echo 'mount success!' # 将挂载信息写入fstabecho '[rhel]name=rhelbaseurl=file:///mntgpgcheck=0enabled=1' >> /etc/yum.repos.d/rhel.repo #yum源的配置文件yum makecache &> /dev/nullif [ $? -eq 0 ]then echo "Yum source configuration successfully!"else echo "Yum source configuration failed!"fiyum repolist | grep repolist;;2)read -p "Please enter IP address(Tips:192.168.1.1/24): " IPadread -p "Please enter GATEWAY(Tips:192.168.1.254): " gateread -p "please enter DNS server(Tips:114.114.114.114): " DNSread -p "please enter Please enter the network card name(Tips:ens33,eth0): " name nmcli connection modify $name ipv4.method manualnmcli connection modify $name ipv4.addresses $IPadnmcli connection modify $name ipv4.dns $DNS ipv4.gateway $gatenmcli connection modify $name connection.autoconnect yessystemctl restart network if [ $? -eq 0 ]then echo "Network configuration successful!"ifconfig | awk 'NR==2'else echo "Network configuration failed!" fi;;3)yum install -y nfs-utils &> /dev/null #安装nfs服务端if [ $? -eq 0 ]then echo 'NFS service installed successfully!'read -p 'Please enter NFS directory path you want to share(Tips:/nfsdir): ' nfsdir #输入nfs共享的目录sleep 1 read -p 'Please enter the IP address of the host allowed to be shared(Tips:192.168.1.1 or 192.168.1.*): ' nfsIP #输入允许共享的主机IP地址或者网段sleep 1read -p 'Please enter the permission of the shared host(Tips:sync,rw,ro): ' nfspwr #输入允许共享的主机的权限sleep 1echo "Configuring..... Please wait."sleep 10if [ -e $nfsdir ] #判断nfs共享目录是否存在then echo 'File Exists'else mkdir $nfsdirchmod -Rf 777 $nfsdirfiecho "$nfsdir $nfsIP($nfspwr)" > /etc/exports systemctl restart nfs-server if [ $? -eq 0 ] then IP=`ifconfig | awk -F ' ' 'NR==2{print$2}'` #使用awk命令提取出IP地址exportfs -r showmount -e $IPif [ $? -eq 0 ] #判断服务是否配置正确then echo "NFS server has been configured successfully!"else echo "NFS server has been configured failed!"fifisystemctl restart rpcbind systemctl enable rpcbind &> /dev/nullsystemctl enable nfs-server &> /dev/null #加入到开机自启动firewall-cmd --add-service=nfs --permanent &> /dev/nullfirewall-cmd --add-service=rpc-bind --permanent &> /dev/nullfirewall-cmd --reload &> /dev/nullelse echo 'NFS service installion failed!'fi;;4)yum install -y dhcp &> /dev/nullif [ $? -eq 0 ]then read -p "Please enter the type of DNS service dynamic update(Tips:none,interim,ad-hoc): " styleread -p "Allow/ignore client update DNS records(Tips:allow/ignore): " judgeread -p "Please enter a DNS domain(Tips:roya.com): " domain IP=`ifconfig | awk -F ' ' 'NR==2{print$2}'` NETMASK=`ifconfig | awk -F ' ' 'NR==2{print$4}'`IP0="echo "`ifconfig | awk -F ' ' 'NR==2{print$2}' | cut -d '.' -f 1,2,3`.0""IP1="expr `ifconfig| awk -F ' ' 'NR==2{print$2}'  | awk -F '.' '{print$4}'` + 20"IP2="expr `ifconfig| awk -F ' ' 'NR==2{print$2}'  | awk -F '.' '{print$4}'` + 100"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 << EOFddns-update-style $style;$judge client-updates;subnet `$IP0` netmask $NETMASK {range `$IP3` `$IP4`;option subnet-mask $NETMASK;option routers $IP;option domain-name "$domain";option domain-name-servers $IP;default-lease-time 21600;max-lease-time 43200;}EOFsystemctl restart dhcpd if [ $? -eq 0 ]then echo "DHCP service configuration succeeded!"systemctl enable dhcpd &> /dev/nullfirewall --add-service=dhcp --permanent &> /dev/nullfirewall --reload &> /dev/nullsystemctl status dhcpdelse echo "DHCP service configuration failed!"fielse echo "DHCP service not installed successfully!"fi;;*) exit 0;;esac

运行结果如下配置ip地址

3e2c45bd0fb306b6d8d099c88a44bca1.png

搭建DHCP服务

9acc82d476dbc1effc0ed7188b500946.png

本文到此也就结束了,希望能对大家有所帮助,由于水平有限,在很多地方肯定有些不足之处,如有纰漏或者错误,还请斧正,定当改进。文章写的很不容易,大家的评论和点赞就是我的最大动力,谢谢支持!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值