YUM源伺服器搭建與客戶端配置使用

yhdmy發表於2023-02-23

一. YUM源伺服器搭建(httpd方式)

1. 檢查機器資訊

[root@yumserver ~]# hostname
yumserver
[root@yumserver ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
[root@yumserver ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   96G  2.7G   94G   3% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.5M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                197M  121M   77M  62% /boot
tmpfs                    781M     0  781M   0% /run/user/0
/dev/sr0                 4.3G  4.3G     0 100% /mnt/cdrom
[root@yumserver ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:50:56:b7:a8:32 brd ff:ff:ff:ff:ff:ff
    inet 10.129.169.18/24 brd 10.129.169.255 scope global ens192
       valid_lft forever preferred_lft forever
    inet6 fe80::3293:93ff:a9c0:f80e/64 scope link 
       valid_lft forever preferred_lft forever
    inet6 fe80::8b8e:6494:940b:c5e7/64 scope link tentative dadfailed 
       valid_lft forever preferred_lft forever
    inet6 fe80::25ef:615d:61e1:4d36/64 scope link tentative dadfailed 
valid_lft forever preferred_lft forever

2. httpd軟體安裝

[[root@yumserver ~]# yum -y install httpd
[Loaded plugins: fastestmirror
[Loading mirror speeds from cached hostfile
[Resolving Dependencies
[--> Running transaction check
[---> Package httpd.x86_64 0:2.4.6-67.el7.centos will be installed
[--> Processing Dependency: httpd-tools = 2.4.6-67.el7.centos for package: httpd-2.4.6-67.el7.centos.x86_64
[--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-67.el7.centos.x86_64
[--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
[--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-67.el7.centos.x86_64
[--> Running transaction check
[---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
[---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
[---> Package httpd-tools.x86_64 0:2.4.6-67.el7.centos will be installed
[---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
[--> Finished Dependency Resolution
[
[Dependencies Resolved
[
[==================================================================================================================
[ Package                    Arch                  Version                              Repository            Size
[==================================================================================================================
[Installing:
[ httpd                      x86_64                2.4.6-67.el7.centos                  cdrom                2.7 M
[Installing for dependencies:
[ apr                        x86_64                1.4.8-3.el7                          cdrom                103 k
[ apr-util                   x86_64                1.5.2-6.el7                          cdrom                 92 k
[ httpd-tools                x86_64                2.4.6-67.el7.centos                  cdrom                 87 k
[ mailcap                    noarch                2.1.41-2.el7                         cdrom                 31 k
[
[Transaction Summary
[==================================================================================================================
[Install  1 Package (+4 Dependent packages)
[
[Total download size: 3.0 M
[Installed size: 10 M
[Downloading packages:
[------------------------------------------------------------------------------------------------------------------
[Total                                                                              36 MB/s | 3.0 MB  00:00:00     
[Running transaction check
[Running transaction test
[Transaction test succeeded
[Running transaction
[  Installing : apr-1.4.8-3.el7.x86_64                                                                         1/5 
[  Installing : apr-util-1.5.2-6.el7.x86_64                                                                    2/5 
[  Installing : httpd-tools-2.4.6-67.el7.centos.x86_64                                                         3/5 
[  Installing : mailcap-2.1.41-2.el7.noarch                                                                    4/5 
[  Installing : httpd-2.4.6-67.el7.centos.x86_64                                                               5/5 
[  Verifying  : httpd-2.4.6-67.el7.centos.x86_64                                                               1/5 
[  Verifying  : mailcap-2.1.41-2.el7.noarch                                                                    2/5 
[  Verifying  : apr-1.4.8-3.el7.x86_64                                                                         3/5 
[  Verifying  : httpd-tools-2.4.6-67.el7.centos.x86_64                                                         4/5 
[  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                                    5/5 
[
[Installed:
[  httpd.x86_64 0:2.4.6-67.el7.centos                                                                              
[
[Dependency Installed:
[  apr.x86_64 0:1.4.8-3.el7          apr-util.x86_64 0:1.5.2-6.el7     httpd-tools.x86_64 0:2.4.6-67.el7.centos    
[  mailcap.noarch 0:2.1.41-2.el7    
[
[Complete!
[[root@yumserver ~]# systemctl status httpd
[● httpd.service - The Apache HTTP Server
[   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
[   Active: inactive (dead)
[     Docs: man:httpd(8)
[           man:apachectl(8)
[[root@yumserver ~]# systemctl status httpd
[● httpd.service - The Apache HTTP Server
[   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
[   Active: inactive (dead)
[     Docs: man:httpd(8)
[           man:apachectl(8)

3. httpd啟動

[[root@yumserver ~]# systemctl start httpd
[root@yumserver ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@yumserver ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-02-16 14:53:51 CST; 5 days ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 112093 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─ 39745 /usr/sbin/httpd -DFOREGROUND
           ├─ 39746 /usr/sbin/httpd -DFOREGROUND
           ├─ 39747 /usr/sbin/httpd -DFOREGROUND
           ├─ 39748 /usr/sbin/httpd -DFOREGROUND
           ├─ 39749 /usr/sbin/httpd -DFOREGROUND
           ├─ 78937 /usr/sbin/httpd -DFOREGROUND
           └─112093 /usr/sbin/httpd -DFOREGROUND
Feb 16 14:53:51 yumserver systemd[1]: Starting The Apache HTTP Server...
Feb 16 14:53:51 yumserver httpd[112093]: AH00558: httpd: Could not reliably determine the server's fully q...ssage
Feb 16 14:53:51 yumserver systemd[1]: Started The Apache HTTP Server.
Feb 19 03:34:01 yumserver httpd[39743]: AH00558: httpd: Could not reliably determine the server's fully qu...ssage
Feb 19 03:34:01 yumserver systemd[1]: Reloaded The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

4. 配置YUM原始檔,將光碟內容COPY到對應目錄

[root@yumserver ~]# cd /var/www/html/
[root@yumserver html]# ll
total 8
drwxrwxr-x.  7 root root 4096 Feb 14 09:48 Centos6.9
drwxrwxr-x. 10 root root  251 Feb 14 17:50 Centos7.3
drwxrwxr-x.  8 root root  220 Feb  9 14:35 Centos7.4
drwxrwxr-x. 12 root root 4096 Feb 13 11:30 Redhat6.9

5. 對目錄進行yum源庫的建立

[root@yumserver ~]# createrepo /var/www/html/Centos6.9
Spawning worker 0 with 810 pkgs
Spawning worker 1 with 810 pkgs
Spawning worker 2 with 810 pkgs
Spawning worker 3 with 810 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yumserver ~]# createrepo /var/www/html/Centos7.3
Spawning worker 0 with 1208 pkgs
Spawning worker 1 with 1208 pkgs
Spawning worker 2 with 1207 pkgs
Spawning worker 3 with 1207 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@yumserver ~]# createrepo /var/www/html/Centos7.4
Spawning worker 0 with 974 pkgs
Spawning worker 1 with 974 pkgs
Spawning worker 2 with 973 pkgs
Spawning worker 3 with 973 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

6. 客戶端yum配置檔案

cat /etc/yum.repos.d/cdrom.repo
[cdrom]
name=cdrom
baseurl=
enabled=1
gpgcheck=0

7. 客戶端yum測試 

[root@rac1 ~]# yum clean all
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: cdrom
Cleaning up Everything
[root@rac1 ~]# yum repolist
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
cdrom                                                                                      | 2.9 kB     00:00     
cdrom/primary_db                                                                           | 3.1 MB     00:00     
repo id                                                repo name                                            status
cdrom                                                  cdrom                                                3,994
repolist: 3,994
[root@rac1 ~]# yum makecache
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
cdrom                                                                                      | 2.9 kB     00:00     
cdrom/filelists_db                                                                         | 3.4 MB     00:00     
cdrom/other_db                                                                             | 1.3 MB     00:00     
Metadata Cache Created
[root@rac1 ~]# yum install telnet -y
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-48.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================
 Package                  Arch                     Version                          Repository               Size
==================================================================================================================
Installing:
 telnet                   x86_64                   1:0.17-48.el6                    cdrom                    58 k
Transaction Summary
==================================================================================================================
Install       1 Package(s)
Total download size: 58 k
Installed size: 109 k
Downloading Packages:
telnet-0.17-48.el6.x86_64.rpm                                                              |  58 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : 1:telnet-0.17-48.el6.x86_64                                                                    1/1 
  Verifying  : 1:telnet-0.17-48.el6.x86_64                                                                    1/1 
Installed:
  telnet.x86_64 1:0.17-48.el6                                                                                     
Complete!

總結:這次部署的YUM源伺服器採用的是httpd方式,其實也可以透過ftp實現,這個有機會再完善吧。在部署過程中需要注意的如果作業系統沒有安裝httpd,createrpop兩個軟體包,可以先透過掛載cdrom方式,將其裝好。最後再叨嘮兩句,好久沒發文了,不對,是太久太久啦!這次迴歸,希望能給自己學習的道路上再添磚加瓦。Where there is a will, there is a way.

Sam Yang.

2023.02.23


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26148431/viewspace-2936645/,如需轉載,請註明出處,否則將追究法律責任。

相關文章