centos7.6通过rbuild安装软件:RHEL7,Centos7下使用shell脚本一键部署服务

时间:2024-05-08 08:42:03/人气:251 ℃

新增了一键配置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地址

搭建DHCP服务

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

推荐

  • 1佛山一日自驾游攻略_佛山一日游攻略266
  • 2超短的简单的英语笑话378
  • 3关于繁华的现代散文诗歌188
  • 4员工个人心得体会257
  • 5农业经济学认识实习报告263
  • 6爱护环境小学生作文405
  • 7与竹有关的诗句赏析246
  • 8感恩祝福244
  • 9梅雨季节是从什么时候到什么时候?梅雨季节来袭从成因到应对全解析195
  • 10汉语究竟有没有形态变化:汉语一个独一无二的特征决定了其文字没有拼音化318
  • 首页/电脑版/地图
    © 2024 OONiu.Com All Rights Reserved.