centos7 yum离线源部署


#关闭selinux、防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0

#设置hostname
hostnamectl set-hostname yum
#设置固定IP#ifconfig  #查看网卡名NetName=ens37 #网需要设置的网卡rm -f /etc/sysconfig/network-scripts/ifcfg-$NetNamenmcli con add con-name $NetName ifname $NetName autoconnect yes type ethernet \     ip4 172.16.11.25/24 ipv4.dns "172.16.11.14 119.29.29.29" ipv4.gateway "172.16.11.1"nmcli connection reload #重新加载网络

#时间同步
/usr/sbin/ntpdate ntp6.aliyun.com 
echo "*/3 * * * * /usr/sbin/ntpdate ntp6.aliyun.com  &> /dev/null" > /tmp/crontab
crontab /tmp/crontab

#更换阿里源
mv /etc/yum.repos.d/CentOS-Base.repo{,.bak}
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #可选
yum clean all && yum makecache #生成缓存
 

##########################################

#安装createrepo,http服务
yum install createrepo httpd -y

#配置http目录共享
echo '#http share
Alias /share /www/share
<Directory "/www/share">
    Options Indexes FollowSymLinks
    IndexOptions NameWidth=* DescriptionWidth=* FoldersFirst
    IndexOptions SuppressIcon HTMLTable Charset=UTF-8 SuppressHTMLPreamble
    Order allow,deny
    Allow from all
    Require all granted
</Directory>
'>/etc/httpd/conf.d/share.conf
cp /etc/httpd/conf/httpd.conf{,.bak}
echo "
ServerName localhost
#关闭版本号显示
ServerSignature Off
ServerTokens Prod
">>/etc/httpd/conf/httpd.conf
systemctl enable httpd.service
systemctl restart httpd.service
netstat -antp|grep 'httpd'
#浏览器访问 172.16.11.25/share ,能访问即正常

#创建YUM仓库
mkdir -p /var/www/html/linux
createrepo -p /var/www/html/linux

#创建源文件
echo "
[linux]
name=linux
baseurl=http://192.168.2.50/share/linux/
gpgcheck=0
enabled=1
cost=88
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
">/var/www/html/repo/centos6.5.repo
 

#更新源
createrepo --update -p /vaw/www/html/linux 

#客户端使用源
wget -O /var/www/html/repo/centos6.5.repo http://192.168.2.50/repo/centos6.5.repo

posted @ 2021-03-17 17:50  小⑦  阅读(328)  评论(0)    收藏  举报