1.架构图
2.环境准备
复制一个虚拟机,修改MAC地址,ip,主机名等
[root@kylin-10-sp3 ~]# hostnamectl set-hostname kylin-sp3-cllient
[root@kylin-10-sp3 ~]#
[root@kylin-sp3-cllient ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
[root@kylin-sp3-cllient ~]#
角色 | 主机名** | ip****地址** |
---|---|---|
yum源服务器(私有仓库服务器) | Kylin-V10-sp | 10.0.0.36 |
内网机器 | kylin-sp3-cllient | 10.0.0.41 |
3.详细搭建流程
4. yum私有仓库服务器
4.1 下载各种软件并保存到/app/yum/目录
# 开启yum命令缓存功能
[root@Kylin-V10-sp3 ~]# vim /etc/yum.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
# 新增下面两行
keepcache=1
cachedir=/var/cache/yum/# 各种下载软件包 (未来需要准备好所有的软件包)
[root@Kylin-V10-sp3 /var/cache]# mkdir -p /app/yum/
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# yum reinstall -y tree vim lrzsz nmap nc telnet
已重装:lrzsz-0.12.20-46.ky10.x86_64 nmap-2:7.92-1.p01.ky10.x86_64 telnet-1:0.17-77.ky10.x86_64 tree-1.8.0-2.ky10.x86_64 vim-enhanced-2:9.0-19.p03.ky10.x86_64 完毕!
[root@Kylin-V10-sp3 /var/cache]## 复制到/app/yum/目录 find /var/cache/yum/ -name "*.rpm" |xargs cp -t /app/yum/
[root@Kylin-V10-sp3 /var/cache]# find /var/cache/yum -type f *.rpm
find: paths must precede expression: `*.rpm'
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# find /var/cache/yum -type f -name *.rpm
/var/cache/yum/ks10-adv-os-f52f2e63634844ad/packages/lrzsz-0.12.20-46.ky10.x86_64.rpm
/var/cache/yum/ks10-adv-os-f52f2e63634844ad/packages/nmap-7.92-1.p01.ky10.x86_64.rpm
/var/cache/yum/ks10-adv-os-f52f2e63634844ad/packages/tree-1.8.0-2.ky10.x86_64.rpm
/var/cache/yum/ks10-adv-updates-7a569415ba681cab/packages/telnet-0.17-77.ky10.x86_64.rpm
/var/cache/yum/ks10-adv-updates-7a569415ba681cab/packages/vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# cp `find /var/cache/yum/ -type f -name "*.rpm"` /app/yum/
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# ll /app/yum/
总用量 7832
-rw-r--r-- 1 root root 83736 9月 8 01:05 lrzsz-0.12.20-46.ky10.x86_64.rpm
-rw-r--r-- 1 root root 6146064 9月 8 01:05 nmap-7.92-1.p01.ky10.x86_64.rpm
-rw-r--r-- 1 root root 64340 9月 8 01:05 telnet-0.17-77.ky10.x86_64.rpm
-rw-r--r-- 1 root root 52192 9月 8 01:05 tree-1.8.0-2.ky10.x86_64.rpm
-rw-r--r-- 1 root root 1664616 9月 8 01:05 vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /var/cache]#
4.2 通过createrepo命令创建yum仓库的元数据
元数据:属性信息,yum仓库的元数据(仓库软件包列表,名字)
[root@Kylin-V10-sp3 /var/cache]# yum install -y createrepo
已安装:createrepo_c-0.16.0-3.p01.ky10.x86_64 drpm-0.5.0-1.ky10.x86_64 完毕!
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# createrepo /app/yum/
Directory walk started
Directory walk done - 5 packages
Temporary output repo path: /app/yum/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# ll /app/yum/
总用量 7836
-rw-r--r-- 1 root root 83736 9月 8 01:05 lrzsz-0.12.20-46.ky10.x86_64.rpm
-rw-r--r-- 1 root root 6146064 9月 8 01:05 nmap-7.92-1.p01.ky10.x86_64.rpm
drwxr-xr-x 2 root root 4096 9月 8 01:06 repodata
-rw-r--r-- 1 root root 64340 9月 8 01:05 telnet-0.17-77.ky10.x86_64.rpm
-rw-r--r-- 1 root root 52192 9月 8 01:05 tree-1.8.0-2.ky10.x86_64.rpm
-rw-r--r-- 1 root root 1664616 9月 8 01:05 vim-enhanced-9.0-19.p03.ky10.x86_64.rpm
[root@Kylin-V10-sp3 /var/cache]#
4.3 启动nginx配置ngx访问/app/yum/
4.3.1 安装启动nginx
点击查看代码
# 查看是否安装nginx
[root@Kylin-V10-sp3 /var/cache]# rpm -qa |grep nginx
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# rpm -ql nginx
未安装软件包 nginx
[root@Kylin-V10-sp3 /var/cache]#
[root@Kylin-V10-sp3 /var/cache]# cd
[root@Kylin-V10-sp3 ~]#
# 安装nginx
[root@Kylin-V10-sp3 ~]# yum install -y nginx
已安装:gperftools-libs-2.8-1.ky10.x86_64 libunwind-1.3.1-3.ky10.x86_64 nginx-1:1.21.5-2.p02.ky10.x86_64 nginx-all-modules-1:1.21.5-2.p02.ky10.noarch nginx-filesystem-1:1.21.5-2.p02.ky10.noarch nginx-mod-http-image-filter-1:1.21.5-2.p02.ky10.x86_64 nginx-mod-http-perl-1:1.21.5-2.p02.ky10.x86_64 nginx-mod-http-xslt-filter-1:1.21.5-2.p02.ky10.x86_64 nginx-mod-mail-1:1.21.5-2.p02.ky10.x86_64 nginx-mod-stream-1:1.21.5-2.p02.ky10.x86_64 完毕!
[root@Kylin-V10-sp3 ~]#
[root@Kylin-V10-sp3 ~]# rpm -qa |grep nginx
nginx-all-modules-1.21.5-2.p02.ky10.noarch
nginx-mod-http-xslt-filter-1.21.5-2.p02.ky10.x86_64
nginx-mod-stream-1.21.5-2.p02.ky10.x86_64
nginx-filesystem-1.21.5-2.p02.ky10.noarch
nginx-mod-http-perl-1.21.5-2.p02.ky10.x86_64
nginx-1.21.5-2.p02.ky10.x86_64
nginx-mod-http-image-filter-1.21.5-2.p02.ky10.x86_64
nginx-mod-mail-1.21.5-2.p02.ky10.x86_64
[root@Kylin-V10-sp3 ~]#
# 关闭防火墙
[root@Kylin-V10-sp3 ~]# systemctl stop firewalld
[root@Kylin-V10-sp3 ~]#
[root@Kylin-V10-sp3 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: inactive (dead) since Sun 2024-09-08 01:18:25 -03; 3s agoDocs: man:firewalld(1)Process: 837 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)Main PID: 837 (code=exited, status=0/SUCCESS)8月 22 20:57:57 Kylin-V10-sp3 systemd[1]: Starting firewalld - dynamic firewall daemon...
8月 22 20:57:58 Kylin-V10-sp3 systemd[1]: Started firewalld - dynamic firewall daemon.
9月 08 01:18:25 Kylin-V10-sp3 systemd[1]: Stopping firewalld - dynamic firewall daemon...
9月 08 01:18:25 Kylin-V10-sp3 systemd[1]: firewalld.service: Succeeded.
9月 08 01:18:25 Kylin-V10-sp3 systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@Kylin-V10-sp3 ~]#
# 检查80端口
[root@Kylin-V10-sp3 ~]# ss -lntup
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* users:(("chronyd",pid=741,fd=6))
udp UNCONN 0 0 [::1]:323 [::]:* users:(("chronyd",pid=741,fd=7))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=854,fd=5))
tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=854,fd=6))
[root@Kylin-V10-sp3 ~]#
# 检查nginx进程
[root@Kylin-V10-sp3 ~]# ps -ef | grep nginx
root 2312 1315 0 01:20 pts/0 00:00:00 grep nginx
[root@Kylin-V10-sp3 ~]#
# 启动nginx
[root@Kylin-V10-sp3 ~]# systemctl start nginx
[root@Kylin-V10-sp3 ~]#
[root@Kylin-V10-sp3 ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)Active: active (running) since Sun 2024-09-08 01:21:16 -03; 6s agoProcess: 2318 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)Process: 2319 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)Process: 2321 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)Main PID: 2323 (nginx)Tasks: 2Memory: 9.2MCGroup: /system.slice/nginx.service├─2323 nginx: master process /usr/sbin/nginx└─2324 nginx: worker process9月 08 01:21:16 Kylin-V10-sp3 systemd[1]: Starting The nginx HTTP and reverse proxy server...
9月 08 01:21:16 Kylin-V10-sp3 nginx[2319]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
9月 08 01:21:16 Kylin-V10-sp3 nginx[2319]: nginx: configuration file /etc/nginx/nginx.conf test is successful
9月 08 01:21:16 Kylin-V10-sp3 systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@Kylin-V10-sp3 ~]#
4.3.2 检查
4.3.3 修改配置文件
找到/etc/nginx/nginx.conf server部分,修改root和增加autoindex
root /app/yum/;
autoindex on;[root@Kylin-V10-sp3 ~]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf_bak
[root@Kylin-V10-sp3 ~]#
[root@Kylin-V10-sp3 ~]# vim /etc/nginx/nginx.confserver {listen 80;listen [::]:80;server_name _;#root /usr/share/nginx/html;root /app/yum;autoindex on;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;
# 测试检查语法
[root@Kylin-V10-sp3 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@Kylin-V10-sp3 ~]#
[root@Kylin-V10-sp3 ~]# systemctl restart nginx
[root@Kylin-V10-sp3 ~]#
4.3.4 访问与测试
成功提示: 显示/app/yum/内容
5.yum仓库的客户端
5.1 注释现有的配置
[root@kylin-sp3-cllient ~]# cd /etc/yum.repos.d/
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# ll
总用量 8
-rw-r--r-- 1 root root 664 8月 4 2022 epel.repo
-rw-r--r-- 1 root root 701 9月 8 2022 kylin_x86_64.repo
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# gzip *
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# ll
总用量 8
-rw-r--r-- 1 root root 254 8月 4 2022 epel.repo.gz
-rw-r--r-- 1 root root 266 9月 8 2022 kylin_x86_64.repo.gz
[root@kylin-sp3-cllient /etc/yum.repos.d]#
5.2 书写yum仓库配置文件连接内网私有仓库
# 新增yumlocal.repo文件,内容如下
[root@kylin-sp3-cllient /etc/yum.repos.d]# vim yumlocal.repo
[yumlocal]
name=yum local repo
#baseurl地址打开后要能看到repodata目录
#务必浏览器测试后再写入
baseurl=http://10.0.0.36:80/
enabled=1
gpgcheck=0
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# yum clean all
21 文件已删除
# 看到仓库标识为yumlocal,说明是从本地下载的
[root@kylin-sp3-cllient /etc/yum.repos.d]# yum repolist
仓库标识 仓库名称
yumlocal yum local repo
[root@kylin-sp3-cllient /etc/yum.repos.d]#
5.3 检查与测试
点击查看代码
[root@kylin-sp3-cllient /etc/yum.repos.d]# ping qq.com
ping: qq.com: 未知的名称或服务
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# yum reinstall tree -y
yum local repo 1.6 MB/s | 8.8 kB 00:00
依赖关系解决。
===========================================================================================================================================================================Package Architecture Version Repository Size
===========================================================================================================================================================================
重新安装:tree x86_64 1.8.0-2.ky10 yumlocal 51 k事务概要
===========================================================================================================================================================================总下载:51 k
安装大小:115 k
下载软件包:
tree-1.8.0-2.ky10.x86_64.rpm 40 MB/s | 51 kB 00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计 5.0 MB/s | 51 kB 00:00
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务准备中 : 1/1 重新安装: tree-1.8.0-2.ky10.x86_64 1/2 清理 : tree-1.8.0-2.ky10.x86_64 2/2 验证 : tree-1.8.0-2.ky10.x86_64 1/2 验证 : tree-1.8.0-2.ky10.x86_64 2/2 已重装:tree-1.8.0-2.ky10.x86_64 完毕!
[root@kylin-sp3-cllient /etc/yum.repos.d]#
[root@kylin-sp3-cllient /etc/yum.repos.d]# tree -L 2 /etc/
/etc/
├── abrt
│ ├── abrt-action-save-package-data.conf
│ ├── abrt.conf
│ ├── gpg_keys.conf
│ └── plugins