环境:

操作系统:CentOS6.5 64位

内网IP:192.168.20.210


操作步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 1.先挂载CentOS-6.5-x86_64-bin-DVD1.iso
mount -o loop -t iso9660 /dev/cdrom /mnt/
rpm -ivh /mnt/Packages/deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm 
rpm -ivh /mnt/Packages/python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm 
rpm -ivh /mnt/Packages/createrepo-0.9.9-18.el6.noarch.rpm 
mkdir -p /data/www/centos/6/x86_64/
\cp -r /mnt/Packages/ /data/www/centos/6/x86_64/
cp /mnt/RPM-GPG-KEY-CentOS-/data/www/centos/
umount /mnt
 
# 2.然后挂载CentOS-6.5-x86_64-bin-DVD2.iso
mount -o loop -t iso9660 /dev/cdrom /mnt/
\cp -r /mnt/Packages/ /data/www/centos/6/x86_64/
umount /mnt
 
# 3.创建仓库
createrepo /data/www/centos/6/x86_64/
 
# 4.启动nginx
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
cat /etc/nginx/conf.d/yum.repo.conf << EOF
server {
        listen  80;
        server_name localhost;
        root /data/www;
        # 开启Nginx的目录文件列表
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
}
EOF
chmod 755 /data
chown -R nginx. /data/www
service nginx start
chkconfig nginx on
# 测试访问:http://192.168.20.210/centos/6/x86_64/
 
 
# 5.yum源配置
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
cat > CentOS-Base.repo << 'EOF'
[base]
name=CentOS-6 - Base - LAN
baseurl=http://192.168.20.210/centos/6/$basearch/
gpgcheck=1
gpgkey=http://192.168.20.210/centos/RPM-GPG-KEY-CentOS-6
EOF
 
# 6.验证
yum clean all
yum makecache

    当有重大安全升级的时候,操作方法:

1
2
3
4
# 把升级包放入Packages目录后,更新yum源:
createrepo --update /data/www/centos/6/x86_64/
# ansible批量升级内网服务器示例:
ansible -i hosts all -m yum -a 'name=glibc state=latest update_cache=yes disable_gpg_check=yes' -s