码迷,mamicode.com
首页 > 其他好文 > 详细

#centos7 创建内网yum源

时间:2017-10-12 21:34:27      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:fdisk   mod   tmp   host   -o   iso   label   rpm   一个   

#centos7 创建内网yum源
#centos7 自动化安装 本地 内网 web源创建、更新 createrepo http

Elven原创 http://www.cnblogs.com/elvi/p/7657770.html

 

 

# Mady by Elven

#自动化安装centos7
#下载系统镜像
#http://mirrors.aliyun.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
#使用ISO镜像 + ks文件自动化安装
#安装界面选择"Install CentOS7" 按TAB键进入编辑,添加自动化安装脚本 ks=http://elven.vip/ks/c7cd.ks
#按Enter开始自动化安装


#更改grub启动项,更改等待时间,更改字符界面
[ `uname -r` = *el6* ] && { Grubcfg=/boot/grub/grub.cfg; } || { Grubcfg=/boot/grub2/grub.cfg; }
echo  "修改 $Grubcfg"
cp $Grubcfg{,.bak}
sed -i s#timeout=5#timeout=2#g $Grubcfg
sed -i s#rhgb##g $Grubcfg

#关闭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=eth0 #需要设置的网卡eth0
Netfiles=/etc/sysconfig/network-scripts/ifcfg-$Netname 
sed -i s/^BOOTPROTO/#BOOTPROTO/ $Netfiles
sed -i s/^DNS/#DNS/ $Netfiles
echo "
BOOTPROTO="static"
IPADDR="172.16.11.25"
NETMASK="255.255.255.0"
GATEWAY="172.16.11.1"
DNS1="172.16.16.14"
DNS2="119.29.29.29"
" >>$Netfiles

#时间同步
/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 #生成缓存

#--------
#我这里单独使用一个数据盘(可选)
#fdisk快速分区,新建50G
echo -e n\np\n1\n\n+40G\nw | fdisk /dev/sdb
mkfs.ext4 /dev/sdb1
e2label /dev/sdb1 /www
mkdir /www
mount -t ext4 /dev/sdb1 /www
df -h|grep /dev/sdb1
#开机挂载磁盘
echo "mount -t ext4 /dev/sdb1 /www" >>/etc/rc.d/rc.local
tail -1 /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
#--------

#设置yum下载目录
mkdir -p /www/share/yum
cp /etc/yum.conf{,.bak}
sed -i s#^keepcache=0#keepcache=1# /etc/yum.conf
sed -i s/^cachedir/#cachedir/ /etc/yum.conf
sed -ir 3 icachedir=/www/share/yum/$basearch/$releasever \n /etc/yum.conf
head /etc/yum.conf

#安装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 /www/share/centos7_rpm
createrepo -p /www/share/centos7_rpm/

#创建源文件
echo "
[My_share]
name=My_Souce
baseurl=http://172.16.11.25/share/centos7_rpm/
gpgcheck=0
enabled=1
cost=88
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
">/www/share/Lan7.repo


## RPM更新
# yum缓存的rpm包拷贝到/www/share/centos7_rpm/
find /www/share/yum -name *.rpm |sed -r s#.*#mv & /www/share/centos7_rpm/\n#|bash
# #下载没有安装过的包
# yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称
# #下载已经安装过的包
# yum reinstall --downloadonly --downloaddir=/www/share/centos7_rpm/ -y 包名称

#更新源
createrepo --update -p /www/share/centos7_rpm/

##########################################
#rpm下载、yum更新 shell
echo #!/bin/sh
[ $# = 0 ] && {
echo "更新源"
/usr/bin/createrepo --update -p /www/share/centos7_rpm/
} || {
echo "yum下载"
yum install --downloadonly --downloaddir=/www/share/centos7_rpm/ -y $*
echo "更新源"
/usr/bin/createrepo --update -p /www/share/centos7_rpm/
}
>yumd.sh
ln -s $(pwd)/yumd.sh /usr/bin/yumd
chmod +x yumd.sh

# 执行 yumd 更新源
# 执行 yumd 软件1 软件2 ,就会下载相关软件并更新源


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

#客户端使用源
wget -O /etc/yum.repos.d/Lan7.repo http://172.16.11.25/share/Lan7.repo

#客户端测试,查看源名称
yum install httpd

#Elven原创 http://www.cnblogs.com/elvi/p/7657770.html

 

#centos7 创建内网yum源

标签:fdisk   mod   tmp   host   -o   iso   label   rpm   一个   

原文地址:http://www.cnblogs.com/elvi/p/7657770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!