CentOS7下的YUM源服务器搭建
CentOS7下的YUM源服务器搭建注意环境要求环境准备修改hostname关闭防火墙disabled selinux[rootlocalhost ~]# hostnamectl set-hostname --static yum-server[rootyum-server ~]# systemctl disable firewalld --now[rootyum-server ~]# sed -i s/^SELINUX.*/SELINUXdisabled/ /etc/sysconfig/selinux配置服务器端yum安装yum源工具[rootyum-server ~]# yum -y install epel-release.noarch # nginx需要epel源[rootyum-server ~]# yum -y install nginx # 安装nginx[rootyum-server ~]# createrepo yum-utils # 安装repository管理工具配置nginx[rootyum-server nginx]# cd /etc/nginx/[rootyum-server nginx]# cp nginx.conf{,.bak} # 备份备份备份[rootyum-server nginx]# vim nginx.confserver{listen80;server_name localhost;root /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location /{}# 在server段加入以下三段内容autoindex on;# 表示自动在index.html的索引打开autoindex_exact_size on;# 表示如果有文件则显示文件的大小autoindex_localtime on;# 表示显示更改时间以当前系统的时间为准error_page404/404.html;location/40x.html{}error_page500502503504/50x.html;location/50x.html{}}[rootyum-server nginx]# nginx -t # 检测一下nginx语法是否有错nginx: the configurationfile/etc/nginx/nginx.conf syntax is ok nginx: configurationfile/etc/nginx/nginx.conftestis successful[rootyum-server nginx]# systemctl enable nginx.service --nowCreated symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.[rootyum-server nginx]# systemctl enable nginx.service --now # 启动nginx设为开机自启[rootyum-server nginx]# curl -I http://localhost # 访问本地状态码返回200服务正常HTTP/1.1200OK Server: nginx/1.16.1 Date: Sun, 05 Jul202009:48:05 GMT Content-Type: text/html Content-Length:4833Last-Modified: Fri,16May201415:12:48 GMT Connection: keep-alive ETag:53762af0-12e1Accept-Ranges: bytes配置nginx页面目录[rootyum-server nginx]# cd /usr/share/nginx/html/[rootyum-server html]# mkdir -p CentOS-YUM/Aliyun/{version_6,version_7}/64bit[rootyum-server html]# tree /usr/share/nginx/html/CentOS-YUM//usr/share/nginx/html/CentOS-YUM/ └── Aliyun ├── version_6 │ └── 64bit └── version_7 └── 64bit5directories,0files[rootyum-server html]# cd CentOS-YUM/ [rootyum-server CentOS-YUM]# vim index.htmlpstylefont-weight:bolder;color:green;font-size:30px;ALL of the packages in the below:/pbr/ahrefhttp://192.168.57.133/CentOS-YUM/Aliyunversion_6/abr/These packagers using for Centos 6br/ahrefhttp://192.168.57.133/CentOS-YUM/Aliyunversion_7/abr/These packagers using for Centos 7br/pstylefont-weight:bolder;color:red;font-size:18px;Please replace the file and fill in the f ollowing content:/ppstylefont-weight:bolder;color:blue;font-size:15px;Way: /etc/yum.repos.d/CentOS-Base.repo/ p替换yum源文件# 备份原来的官方yum源[rootyum-server CentOS-YUM]# cd /etc/yum.repos.d/[rootyum-server yum.repos.d]# mv ./* /tmp/[rootyum-server yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo # 下载aliyun的centos7的yum源[rootyum-server yum.repos.d]# vim yum.reposync.sh # 同步脚本#!/usr/bin/bashreposync-p/usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/ /usr/bin/sed-is/7/6/ggrep7-rl/etc/yum.repos.d/CentOS-Base.reporeposync-p/usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/ /usr/bin/sed-is/6/7/ggrep6-rl/etc/yum.repos.d/CentOS-Base.repo[rootyum-server yum.repos.d]# chmod x yum.reposync.sh # 要给执行权限[rootyum-server yum.repos.d]# lltotal8-rw-r--r--1root root2523Jun162018CentOS-Base.repo -rwxr-xr-x1root root303Jul519:02 yum.reposync.sh[rootyum-server yum.repos.d]# sh yum.reposync.sh# 等待同步完成# 同步完成查看文件大小合计27G[rootyum-server CentOS-YUM]# du -ch Aliyun/9.0G Aliyun/version_7/64bit/base/Packages9.0G Aliyun/version_7/64bit/base 616M Aliyun/version_7/64bit/extras/Packages 616M Aliyun/version_7/64bit/extras3.6G Aliyun/version_7/64bit/updates/Packages3.6G Aliyun/version_7/64bit/updates 14G Aliyun/version_7/64bit 14G Aliyun/version_79.0G Aliyun/version_6/64bit/base/Packages9.0G Aliyun/version_6/64bit/base 616M Aliyun/version_6/64bit/extras/Packages 616M Aliyun/version_6/64bit/extras3.6G Aliyun/version_6/64bit/updates/Packages3.6G Aliyun/version_6/64bit/updates 14G Aliyun/version_6/64bit 14G Aliyun/version_6 27G Aliyun/ 27G total建立yum源仓库因为建仓最终的目的也是可供client来进行检索的所以得每个Packages目录都要建成仓库所以建仓的时候目录指到最底层的Packages,而-np更新的时候只用指定到64bit的目录就可以了否则会重复建立base、extras、updates三个目录进行下载[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/base/Packages/Spawning worker0with10070pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/extras/Packages/Spawning worker0with397pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/updates/Packages/Spawning worker0with884pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/base/Packages/Spawning worker0with10070pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/updates/Packages/Spawning worker0with884pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# createrepo -p /usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/extras/Packages/Spawning worker0with397pkgs Workers Finished Saving Primary metadata Savingfilelists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete[rootyum-server ~]# tree -d /usr/share/nginx/html/CentOS-YUM/Aliyun/ # 建仓完成后会自动生成一个repodata目录/usr/share/nginx/html/CentOS-YUM/Aliyun/ ├── version_6 │ └── 64bit │ ├── base │ │ └── Packages │ │ └── repodata │ ├── extras │ │ └── Packages │ │ └── repodata │ └── updates │ └── Packages │ └── repodata └── version_7 └── 64bit ├── base │ └── Packages │ └── repodata ├── extras │ └── Packages │ └── repodata └── updates └── Packages └── repodata22directories可以写一个更新yum源的脚本然后写一个计划任务定期更新yum源reposync-np就是更新新的rpm包#!/usr/bin/bashreposync-np/usr/share/nginx/html/CentOS-YUM/Aliyun/version_7/64bit/echocentos7 is sync complate/usr/bin/sed-is/7/6/ggrep7-rl/etc/yum.repos.d/CentOS-Base.reporeposync-np/usr/share/nginx/html/CentOS-YUM/Aliyun/version_6/64bit/echocentos6 is sync complate/usr/bin/sed-is/6/7/ggrep6-rl/etc/yum.repos.d/CentOS-Base.repo配置客户端yum# 备份原来的yum源[rootlocalhost ~]# cd /etc/yum.repos.d/[rootlocalhost yum.repos.d]# lsCentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo epel-testing.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo epel.repo[rootlocalhost yum.repos.d]# mkdir back[rootlocalhost yum.repos.d]# mv CentOS-* back/[rootlocalhost yum.repos.d]# mv epel* back/[rootlocalhost yum.repos.d]# lsback[rootlocalhost yum.repos.d]#[rootlocalhost yum.repos.d]# vim CentOS-Base.repo # 需要6就使用6需要7就使用7也可以使用yum-plugin-priorities工具来控制优先级加上priority12|3|4都可以来控制优先级[Aliyun_7_base]namesource_from_localserverbaseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/base/Packagesgpgcheck0enable1[Aliyun_7_extras]namesource_from_localserverbaseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/extras/Packagesgpgcheck0enable1[Aliyun_7_updates]namesource_from_localserverbaseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_7/64bit/updates/Packagesgpgcheck0enable1# [Aliyun_6_base]# namesource_from_localserver# baseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_6/4bit/base/Packages# gpgcheck0# enable1## [Aliyun_6_extras]# namesource_from_localserver# baseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_6/74bit/extras/Packages# gpgcheck0# enable1## [Aliyun_6_updates]# namesource_from_localserver# baseurlhttp://192.168.57.133/CentOS-YUM/Aliyun/version_6/74bit/updates/Packages# gpgcheck0# enable1[rootlocalhost yum.repos.d]# yum clean all[rootlocalhost yum.repos.d]# yum makecache# 安装软件来测试一下[rootlocalhost yum.repos.d]# yum -y install net-toolsLoaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile Resolving Dependencies --Running transaction check ---Package net-tools.x86_640:2.0-0.25.20131004git.el7 will be installed --Finished Dependency Resolution Dependencies ResolvedPackage Arch Version Repository SizeInstalling: net-tools x86_642.0-0.25.20131004git.el7 Aliyun_7_base306k Transaction SummaryInstall1Package Total download size:306k Installed size:917k Downloading packages: net-tools-2.0-0.25.20131004git.el7.x86_64.rpm|306kB 00:00:00 Running transaction check Running transactiontestTransactiontestsucceeded Running transaction Installing:net-tools-2.0-0.25.20131004git.el7.x86_641/1 Verifying:net-tools-2.0-0.25.20131004git.el7.x86_641/1 Installed: net-tools.x86_640:2.0-0.25.20131004git.el7 Complete!