centos7.6通过rbuild安装软件: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地址
搭建DHCP服务
本文到此也就结束了,希望能对大家有所帮助,由于水平有限,在很多地方肯定有些不足之处,如有纰漏或者错误,还请斧正,定当改进。文章写的很不容易,大家的评论和点赞就是我的最大动力,谢谢支持!
- 03-10创意毕业照学士服和正常衣服 师生设计的原创毕业服一亮相
- 02-04插混油电混增程式哪个好?什么是增程式,油电混插电混
- 02-03九寨沟旅游自驾游最佳路线 最详细九寨沟自驾游线路及攻略
- 05-12菌菇怎样油炸才好吃:厨师长分享脆皮糊调制方法
- 11-22玛莎拉蒂吉博力租车为什么很贵?花160万买辆玛莎拉蒂吉博力做租车
- 09-13手机无信号的解决方法有哪些?手机信号之下篇,手机没信号
- 03-03青海沙漠光伏大基地:青海戈壁荒滩兴起光伏海
- 05-16airpods单独一只怎么连接iphone?除了,iPhone以外
- 04-29小熊美术与美术宝哪个好?线上美术选哪家小熊美术
- 02-05坟上长出狗尾巴草的传说,老农拔下坟头树枝道士道
- 04-18陶粒水培蝴蝶兰新手:如何水培蝴蝶兰
- 02-27淘宝上ar是什么?是不是一个必要的虚构
- 01-30地球太阳银河系儿歌:儿歌中的天体物理学
- 02-13上班经常背痛是怎么回事?工作坐久了背痛顺手做多5件事
- 12-05兰州旅游文字攻略大全最新:游记,兰州心灵的融合
- 02-07平潭7路公交车恢复运行了吗?K1路公交线路将恢复运行
热门
推荐
- 1幼儿园春游活动计划书汇编227
- 2记一件难忘的事的满分作文265
- 3电脑的安全模式进入方法254
- 4将无线路由器恢复了出厂设置结果连不上网怎么办195
- 5小学生消防安全宣传口号455
- 6电脑网络正常打不开网页怎么办373
- 7精华安全承诺书合集九篇362
- 8交通协管换位体验活动策划书178