shell脚本实例-安装httpd,安装yum源

1.安装httpd

#!/usr/bin/bash

getway=192.168.1.1

ping -c1 www.baidu.com &>/dev/null

if [ $? -eq 0 ];then

yum -y install httpd

systemctl start httpd

systemctl enable httpd

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-service=https

firewall-cmd --reload

sed -ri '/^SELINUX=/cSELINUX=disabled/' /etc/selinux/config

setenforce 0

elif ping -c1 $getway &>/dev/null;then

echo "check dns..."

else

echo "check ip address!"

fi

2.安装yum源

#!/usr/local/bash

yum_server=192.168.234.137

#注意在print的时候外面的引号需要单引号

os_version=`cat /etc/redhat-release |awk '{print $4}'|awk -F"." '{print $1."."$2}'`

[ -d /etc/yum.repos.d ] || mkdir /etc/yum.repos.d/bak

mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak

case "$os_version" in

7.4)

cat >/etc/yum.repos.d/centos7.4 <<-EOF

[centos7.4]

name=centos7.4

baseurl=ftp://$yum_server/centos7.4

gpgcheck=0

EOF

echo "7.4 yum configure..."

;;

6.8)

curl -o /eetc/yum.repos.d/centos6u8.repo ftp://$yum_server/centos6u8.repo

;;

*)

echo "error"

esac

作者简介: 
陈志珂(头条号:强扭的瓜不好吃)目前就职于中国最大的安卓应用软件公司,任高级工程师现在公司任php开发工程师,python开发工程师,高级运维工程师,公众号“铅笔学园”运维内容合作作者之一。
铅笔学园:IT资源分享|知识分享,做初级程序员的指明灯

猜你喜欢

转载自www.cnblogs.com/qianbixueyuan/p/9452564.html
今日推荐