来源:Linux社区 作者:nidey < CentOS7.2 创建本地YUM源和局域网YUM源 >
1 # 安装 2 3 # 3.1本地YUM源 4 5 # 3.1.1 ISO源 6 7 # 准备rpm包 8 9 # 挂载CentOS-7-x86_64-Everything-1511.iso,把里面所有文件都拷贝到本地目录/yum/yum-iso 10 11 [root@linuxidc.com ~]# mkdir /mnt/yum-iso 12 [root@linuxidc.com ~]# mount /dev/cdrom /mnt/yum-iso/ 13 mount: /dev/sr0 is write-protected, mounting read-only 14 [root@linuxidc.com ~]# mkdir /yum/ 15 [root@linuxidc.com ~]# cp -a /mnt/yum-iso/ /yum/ 16 [root@linuxidc.com ~]# ll /yum/ 17 total 4 18 dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso 19 [root@linuxidc.com ~]# ll /yum/yum-iso/ 20 total 640 21 -r--r--r--. 1 root root 14 Dec 10 2015 CentOS_BuildTag 22 dr-xr-xr-x. 3 root root 33 Dec 10 2015 EFI 23 -r--r--r--. 1 root root 215 Dec 10 2015 EULA 24 -r--r--r--. 1 root root 18009 Dec 10 2015 GPL 25 dr-xr-xr-x. 3 root root 69 Dec 10 2015 images 26 dr-xr-xr-x. 2 root root 4096 Dec 10 2015 isolinux 27 dr-xr-xr-x. 2 root root 41 Dec 10 2015 LiveOS 28 dr-xr-xr-x. 2 root root 483328 Dec 10 2015 Packages 29 dr-xr-xr-x. 2 root root 4096 Dec 10 2015 repodata 30 -r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-7 31 -r--r--r--. 1 root root 1690 Dec 10 2015 RPM-GPG-KEY-CentOS-Testing-7 32 -r--r--r--. 1 root root 2883 Dec 10 2015 TRANS.TBL 33 [root@linuxidc.com ~]# 34 35 # 备份、移除其他repo 36 37 [root@linuxidc.com ~]# cd /etc/yum.repos.d/ 38 [root@linuxidc.com yum.repos.d]# ll 39 -rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo 40 -rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo 41 -rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo 42 -rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo 43 -rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo 44 -rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo 45 -rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo 46 [root@linuxidc.com yum.repos.d]# tar zcvf repo-bk.tar.gz CentOS-* 47 CentOS-Base.repo 48 CentOS-CR.repo 49 CentOS-Debuginfo.repo 50 CentOS-fasttrack.repo 51 CentOS-Media.repo 52 CentOS-Sources.repo 53 CentOS-Vault.repo 54 [root@linuxidc.com yum.repos.d]# rm -f CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Sources.repo CentOS-Vault.repo 55 56 57 # 配置本地repo 58 59 [root@linuxidc.com yum.repos.d]# vi CentOS-Media.repo 60 61 # 填入如下内容 62 63 [c7-media] 64 name=CentOS-$releasever - Media 65 baseurl=file:///yum/yum-iso/ 66 gpgcheck=0 67 enabled=1 68 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 69 70 # 注释:配置repo路径、关闭gbp校验、启用这个repo 71 72 # 制作cache 73 74 [root@linuxidc.com yum.repos.d]# yum clean all 75 Loaded plugins: fastestmirror 76 Cleaning repos: c7-media 77 Cleaning up everything 78 Cleaning up list of fastest mirrors 79 [root@linuxidc.com yum.repos.d]# yum makecache 80 Loaded plugins: fastestmirror 81 c7-media | 3.6 kB 00:00:00 82 (1/4): c7-media/group_gz | 155 kB 00:00:00 83 (2/4): c7-media/primary_db | 5.3 MB 00:00:00 84 (3/4): c7-media/filelists_db | 6.2 MB 00:00:00 85 (4/4): c7-media/other_db | 2.3 MB 00:00:00 86 Determining fastest mirrors 87 Metadata Cache Created 88 [root@linuxidc.com yum.repos.d]# 89 90 # 这样就可以使用yum安装软件啦 91 92 [root@linuxidc.com yum.repos.d]# yum groupinstall "Development tools" 93 Loaded plugins: fastestmirror 94 There is no installed groups file. 95 Maybe run: yum groups mark convert (see man yum) 96 Loading mirror speeds from cached hostfile 97 Resolving Dependencies 98 --> Running transaction check 99 ---> Package autoconf.noarch 0:2.69-11.el7 will be installed 100 --> Processing Dependency: perl >= 5.006 for package: autoconf-2.69-11.el7.noarch 101 --> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch 102 --> Processing Dependency: perl(warnings) for package: autoconf-2.69-11.el7.noarch 103 104 # 或者 105 106 [root@linuxidc.com yum.repos.d]# yum install tree 107 Loaded plugins: fastestmirror 108 Loading mirror speeds from cached hostfile 109 Resolving Dependencies 110 --> Running transaction check 111 ---> Package tree.x86_64 0:1.6.0-10.el7 will be installed 112 --> Finished Dependency Resolution 113 114 # 3.1.2 自定义YUM源 115 116 [root@linuxidc.com yum.repos.d]# yum -y install createrepo 117 118 # 准备rpm包 119 120 # (需要自己确定依赖包)、目录。这里使用tree做演示。 121 122 [root@linuxidc.com ~]# mkdir -p /yum/yum-custom/packages 123 [root@linuxidc.com ~]# cp tree-1.6.0-10.el7.x86_64.rpm /yum/yum-custom/packages/ 124 125 # 创建repo 126 127 [root@linuxidc.com ~]# createrepo -u -d /yum/yum-custom/ 128 Spawning worker 0 with 1 pkgs 129 Spawning worker 1 with 0 pkgs 130 Workers Finished 131 Saving Primary metadata 132 Saving file lists metadata 133 Saving other metadata 134 Generating sqlite DBs 135 Sqlite DBs complete 136 [root@linuxidc.com ~]# ll /yum/yum-custom/ 137 total 4 138 drwxr-xr-x. 2 root root 41 Dec 20 07:03 packages 139 drwxr-xr-x. 2 root root 4096 Dec 20 07:08 repodata 140 [root@linuxidc.com ~]# 141 142 # 配置自定义repo 143 144 [root@linuxidc.com ~]# vi /etc/yum.repos.d/CentOS-Media.repo 145 146 # 填入如下内容 147 148 [c7-media] 149 name=CentOS-$releasever - Media 150 baseurl=file:///yum/yum-custom/ 151 gpgcheck=0 152 enabled=1 153 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 154 155 # 制作cache 156 157 [root@linuxidc.com ~]# yum clean all 158 Loaded plugins: fastestmirror 159 Cleaning repos: c7-media 160 Cleaning up everything 161 Cleaning up list of fastest mirrors 162 [root@linuxidc.com ~]# 163 [root@linuxidc.com ~]# yum makecache 164 Loaded plugins: fastestmirror 165 c7-media | 3.0 kB 00:00:00 166 (1/3): c7-media/filelists_db | 880 B 00:00:00 167 (2/3): c7-media/primary_db | 1.8 kB 00:00:00 168 (3/3): c7-media/other_db | 1.3 kB 00:00:00 169 Determining fastest mirrors 170 Metadata Cache Created 171 [root@linuxidc.com ~]# 172 173 # 使用自定义repo 174 175 [root@linuxidc.com ~]# yum install tree 176 Loaded plugins: fastestmirror 177 Loading mirror speeds from cached hostfile 178 Resolving Dependencies 179 --> Running transaction check 180 ---> Package tree.x86_64 0:1.6.0-10.el7 will be installed 181 --> Finished Dependency Resolution 182 183 # 3.2 局域网YUM源 184 185 # 局域网YUM源可以配成:本地YUM源 + FTP服务器 186 187 # 这里使用自定义源yum-custom(见上面) + VSFTP演示。 188 189 # 下载vsftpd 190 191 [root@linuxidc.com ~]# yum -y install vsftpd 192 193 # 配置vsftpd 194 195 # 编辑vsftp.conf 196 197 [root@linuxidc.com ~]# vi /etc/vsftpd/vsftpd.conf 198 199 # 并增加匿名用户root目录(默认已经启用匿名访问) 200 201 anon_root=/yum/ 202 203 # 注意目录权限如下 204 205 [root@linuxidc.com ~]# ll -a /yum/ 206 total 8 207 drwxr-xr-x. 4 root root 37 Dec 20 07:37 . 208 dr-xr-xr-x. 18 root root 4096 Dec 20 06:32 .. 209 drwxr-xr-x. 4 root root 36 Dec 20 07:08 yum-custom 210 dr-xr-xr-x. 8 root root 4096 Dec 10 2015 yum-iso 211 212 # 关闭selinux 213 214 # 临时 215 216 [root@linuxidc.com ~]# setenforce 0 217 218 # 或者,永久: 219 220 # 编辑config 221 222 [root@linuxidc.com ~]# vi /etc/selinux/config 223 224 # 设置 225 226 SELINUX=disabled 227 228 # 重启 229 230 [root@linuxidc.com ~]# reboot 231 232 # 启用vsftp 233 234 [root@linuxidc.com ~]# systemctl start vsftpd 235 [root@linuxidc.com ~]# systemctl enable vsftpd 236 Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service. 237 [root@linuxidc.com ~]# 238 239 # 局域网使用 240 241 # 局域网另外一台机器min-client, 242 243 # 配置repo 244 245 # 编辑repo 246 247 [root@min-client ~]# vim /etc/yum.repos.d/CentOS-Media.repo 248 249 # 内容如下 250 251 [c7-media] 252 name=CentOS-$releasever - Media 253 baseurl=ftp://192.168.118.133/yum-custom 254 gpgcheck=0 255 enabled=1 256 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 257 258 # 其中192.168.118.133为上面vsftp服务器地址 259 260 # 启用这个局域网的repo 261 262 [root@min-client ~]# yum clean all 263 Loaded plugins: fastestmirror 264 Cleaning repos: c7-media 265 Cleaning up everything 266 [root@min-client ~]# yum makecache 267 Loaded plugins: fastestmirror 268 c7-media | 3.0 kB 00:00 269 (1/3): c7-media/filelists_db | 880 B 00:00 270 (2/3): c7-media/other_db | 1.3 kB 00:00 271 (3/3): c7-media/primary_db | 1.8 kB 00:00 272 Determining fastest mirrors 273 Metadata Cache Created 274 [root@min-client ~]# 275 276 # 使用 277 278 [root@linuxidc.com ~]# yum -y install tree 279 Loaded plugins: fastestmirror 280 Loading mirror speeds from cached hostfile 281 Resolving Dependencies 282 --> Running transaction check 283 ---> Package tree.x86_64 0:1.6.0-10.el7 will be installed 284 --> Finished Dependency Resolution 285 # 286 # 目前差不多这些就够用了。以后有时间把163的YUM源爬下来,当本地源用。 287