LoginSignup
1
0

VirtualBoxでローカルリポジトリの構築をしてみた

Posted at

はじめに

ネットワーク内部にリポジトリサーバーを構築してみて動作検証してみました。

リポジトリとは
パッケージを格納している場所です。
以下のサイトを参考にしました。
https://wa3.i-3-i.info/word15664.html

通常、Yumはインターネット上のリモートリポジトリからパッケージをインストールしますが、
createrepoを使用することで、ローカルに独自のリポジトリを作成し、そこからパッケージをインストール出来ます。

構成図

VirtualBoxにてリポジトリサーバーとクライアントを構築しました。
CentOS7
image.png

ローカルリポジトリの構築手順

リポジトリサーバー側作業

createrepoコマンドをインストールする

# yum install createrepo

リポジトリ格納用ディレクトリ作成

-pオプションを付けることでフォルダをまとめて作成出来ます。

/var/www/html/repoフォルダを作成後、/var/www/html/repoフォルダに移動してカレントディレクトリを表示します。

# mkdir -p /var/www/html/repo;cd /var/www/html/repo;pwd

bcパッケージをダウンロードした

#  yumdownloader --disablerepo=* --enablerepo=base bc

httpdのrpmパッケージがダウンロードされていることを確認した。

# ls -l /var/www/html/repo
total 120
-rw-r--r--. 1 root root 117272 Jul  4  2014 bc-1.06.95-13.el7.x86_64.rpm
drwxr-xr-x. 2 root root   4096 Aug 20 23:00 repodata

リポジトリを作成する

現在のカレントディレクトリを確認する

# pwd
/var/www/html/repo

リポジトリを作成する

# createrepo .
出力結果
Spawning worker 0 with 1 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

クライアント側作業

リポジトリの設定ファイルを作成する

# vi /etc/yum.repos.d/remote.repo

# [remote]
name=remote
baseurl=http://192.168.0.30/repo
gpgcheck=0

yumリポジトリを更新する

# yum clean all
出力結果
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror


File contains no section headers.
file: file:///etc/yum.repos.d/remote.repo, line: 2
'name=remote\n'

ローケルにエラーが出てました。
「Failed to set locale, defaulting to C」

以下のQiitaの記事が大変参考になりました。
https://qiita.com/ponsuke0531/items/699fcc0eca59f9b10217

対応した内容
LCの環境変数がない事を確認した

#  printenv | grep LC

LC_ALLの設定をした

export LC_ALL=C

再度、# yum clean allを実行したら、
「Failed to set locale, defaulting to C」が消えてました。

[root@server1 ~]# yum clean all
Loaded plugins: fastestmirror


File contains no section headers.
file: file:///etc/yum.repos.d/remote.repo, line: 2

リポジトリの設定ファイルが不備が原因でした

「File contains no section headers.」のエラーの原因は
[remote]の行頭に#が入っていたため、削除しました。

# vi /etc/yum.repos.d/remote.repo

[remote]
name=remote
baseurl=http://192.168.0.30/repo
gpgcheck=0

yum clean allでうまくいきました。

# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras remote updates

補足情報

クライアントサーバーからリポジトリにcurlを実行すると「No route to host」になった

[root@server1 ~]# curl http://192.168.0.30/repo
curl: (7) Failed connect to 192.168.0.30:80; No route to host

リポジトリサーバーにhttpdのポートを許可した
httpdを許可したら、解決出来ました。

[root@localhost ~]# firewall-cmd --add-service=http --zone=public --permanent
success
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# firewall-cmd --reload
success

ローカルリポジトリが問題なく作成できたか確認した

ローカルリポジトリ経由でbcパッケージを表示出来たため、問題なくローカルリポジトリが設定されていることを確認しました。

# yum --disablerepo=\* --enablerepo=remote list bc

出力結果
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
bc.x86_64                                             1.06.95-13.el7                                              remote
[root@server1 ~]#

ローカルリポジトリからbcをダウンロードしました

yumコマンドでremoteからbcパッケージをインストールしました。

yum --disablerepo=\* --enablerepo=remote install bc

出力結果
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bc.x86_64 0:1.06.95-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                Arch                       Version                             Repository                  Size
========================================================================================================================
Installing:
 bc                     x86_64                     1.06.95-13.el7                      remote                     115 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total download size: 115 k
Installed size: 215 k
Is this ok [y/d/N]: y
Downloading packages:
bc-1.06.95-13.el7.x86_64.rpm                                                                     | 115 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : bc-1.06.95-13.el7.x86_64                                                                             1/1
  Verifying  : bc-1.06.95-13.el7.x86_64                                                                             1/1

Installed:
  bc.x86_64 0:1.06.95-13.el7

Complete!

まとめ

今回ハンズオンでつまずくところもありましたが何とか構築することが出来ました。
通常、Yumはインターネット上のリモートリポジトリからパッケージをインストールしますが、
セキュリティ的にネットワークにアクセスできないサーバーのためにシステム内にリポジトリーサーバーを作成する場合があります。
個人的にはインフラエンジニアのお仕事をする場合は、実務でリポジトリサーバーを使用するケースもあるため、ハンズオンしてイメージを掴むで置いた方が良いです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0