GNU/Linux >> Linux の 問題 >  >> Arch Linux

ArchLinuxでReflectorを使用して最新のミラーリストを取得する

Arch Linuxで最新のミラーリストを維持することには、いくつかの大きな利点があります。更新されたミラーリストを使用すると、ダウンロード速度の低下や、パッケージのインストールおよび更新中のエラーメッセージのタイムアウトを簡単に回避できます。このチュートリアルでは、リフレクターとは何かについて説明します。 リフレクターを使用してArchLinuxで最新のミラーリストを取得する方法。

リフレクターとは何ですか?

リフレクター はシンプルなPython3モジュールおよびスクリプトであり、ミラーステータスから速度でソートされた最新のミラーリストをチェックして取得します。 ページを作成し、/etc/pacman.d/mirrorlistに保存します ArchLinuxシステムのファイル。

通常、 /etc/pacman.d/mirrorlist ファイルには、国ごとに1つのミラーサーバーが含まれます。ただし、国ごとに複数のサーバーが存在する必要がありますが、ミラーリストファイルには通常1つしかありません。

では、Arch Linuxで選択した最新の最新のミラーリストをどのように追加または取得しますか?ここがリフレクターです 助けになります。

Reflectorは、速度、国、および経過時間(最後のサーバー同期)に基づいて、最新および最速のArchLinuxミラーのリストを取得してフィルタリングします。

Reflectorは無料のオープンソースPythonスクリプトであり、ArchLinuxとその派生物(EndeavourOSやManjaro Linuxなど)で問題なく動作します。

1。 Arch Linux、EndeavourOS、ManjaroにReflectorをインストールする

Arch LinuxおよびEndeavourOSやManjaroなどのそのバリアントにReflectorをインストールするには、ターミナルから次のコマンドを実行します。

$ sudo pacman -S reflector rsync curl

上記のコマンドは、依存関係のrsyncおよびcurlパッケージとともにReflectorをインストールします。

2。 ArchLinuxでReflectorを使用して最新のミラーリストを取得する

2.1。現在のミラーリストをバックアップする

Reflectorを実行する前に、デフォルトのミラーリストファイルをバックアップする必要があります。なぜなら、Reflectorはそれを上書きし、既存のミラーリストを新しいものに置き換えます。

現在のミラーリストをバックアップするには、次のコマンドを実行します。

$ sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak

2.2。最新のNミラーを取得し、ダウンロード率で並べ替えます

最新のミラートップ20を取得し、ダウンロードレートでミラーリストを並べ替えて、/etc/pacman.d/mirrorlistに保存しましょう。 コマンドを使用したファイル:

$ sudo reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist

これにより、既存のミラーが新しいミラーに置き換えられることに注意してください。

上記のコマンドを分解して、各オプションの機能を見てみましょう。

  • --latest 20 -最後に同期されたサーバーをフェッチします
  • --protocol https -httpsを取得します 有効なミラー
  • --sort rate -ダウンロードレートに基づいてミラーリストを並べ替えます
  • --save /etc/pacman.d/mirrorlist -

/etc/pacman.d/mirrorlistのコンテンツを一覧表示することで確認できます ファイル。

$ cat /etc/pacman.d/mirrorlist

出力例:

 #####################################################################
 ########### Arch Linux mirrorlist generated by Reflector  ###########
 #####################################################################
 With:       reflector --latest 20 --protocol https --sort rate --save /etc/pacman.d/mirrorlist
 When:       2021-06-10 09:51:51 UTC
 From:       https://www.archlinux.org/mirrors/status/json/
 Retrieved:  2021-06-10 09:49:34 UTC
 Last Check: 2021-06-10 09:15:02 UTC
 Server = https://mirror.osbeck.com/archlinux/$repo/os/$arch
 Server = https://asia.mirror.pkgbuild.com/$repo/os/$arch
 Server = https://archlinux.thaller.ws/$repo/os/$arch
 Server = https://arch.mirror.constant.com/$repo/os/$arch
 Server = https://mirror.f4st.host/archlinux/$repo/os/$arch
 Server = https://phinau.de/arch/$repo/os/$arch
 Server = https://mirrors.neusoft.edu.cn/archlinux/$repo/os/$arch
 Server = https://mirror.pseudoform.org/$repo/os/$arch
 Server = https://arch.mirror.square-r00t.net/$repo/os/$arch
 Server = https://mirror.pkgbuild.com/$repo/os/$arch
 Server = https://archlinux.uk.mirror.allworldit.com/archlinux/$repo/os/$arch
 Server = https://archlinux.za.mirror.allworldit.com/archlinux/$repo/os/$arch
 Server = https://mirror.telepoint.bg/archlinux/$repo/os/$arch
 Server = https://mirror.lty.me/archlinux/$repo/os/$arch
 Server = https://mirror.chaoticum.net/arch/$repo/os/$arch
 Server = https://mirror.efect.ro/archlinux/$repo/os/$arch
 Server = https://archmirror.it/repos/$repo/os/$arch
 Server = https://archlinux.mailtunnel.eu/$repo/os/$arch
 Server = https://archlinux.qontinuum.space:4443/$repo/os/$arch
 Server = https://ftp.halifax.rwth-aachen.de/archlinux/$repo/os/$arch

これで、最新の最新ミラーからパッケージをインストール、更新、およびアップグレードできます。

$ sudo pacman -Syu
$ sudo pacman -S <package_name>

2.3。最新のNミラーを取得し、年齢で並べ替える

トップミラーを取得し、それらを経過時間、つまり最後のサーバー同期で並べ替えるには、次のコマンドを実行します。

$ sudo reflector --latest 20 --protocol https --sort age --save /etc/pacman.d/mirrorlist

2.4。国固有のミラーリストを取得する

ミラーを選択した国に制限することもできます。たとえば、インドに住んでいる場合は、インドのサーバーのみでミラーリストを更新することをお勧めします。

世界中で利用可能なすべてのArchLinuxミラーを一覧表示するには、次のコマンドを実行します。

$ reflector --list-countries

出力例:

Country                Code Count
---------------------- ---- -----
Australia                AU    19
Austria                  AT     6
Bangladesh               BD     1
Belarus                  BY     4
Belgium                  BE     3
Bosnia and Herzegovina   BA     2
Brazil                   BR    11
Bulgaria                 BG    11
Canada                   CA    20
Chile                    CL     8
[...]

上記の出力にあるように、リフレクターには、国コードと各国のミラーの数とともに、世界中で利用可能なミラーが一覧表示されます。

このガイドを書いている時点で、ArchLinuxミラーのほとんどは米国にあります。 (134ミラー)、ドイツ (114)、およびオランダ (51)。

特定の国からミラーを取得するには、国名または国コード、あるいはその両方を組み合わせて使用​​できます。

次のコマンドは、インドから上位5つのミラーを取得します 、ダウンロードレートで並べ替えて、ミラーリストファイルに保存します。

$ sudo reflector --verbose --country 'India' -l 5 --sort rate --save /etc/pacman.d/mirrorlist

以下は、上記のコマンドのこれらのフラグが何をするかについての簡単な要約です。

  • --verbose -通常より多くの情報を出力します。
  • --country India -私の好みのミラーの場所。
  • --l 5 -インドの上位5つのミラーを取得します。
  • --sort rate -ダウンロードレートで並べ替えます。
  • --save -ダウンロードしたミラーリストを/etc/pacman-d/mirrorlistに保存します 。

コマンドを使用して、更新されたミラーリストを確認しましょう:

$ cat /etc/pacman.d/mirrorlist

出力例:

################################################################################
################# Arch Linux mirrorlist generated by Reflector #########################
################################################################################

# With:       reflector --verbose --country India -l 5 --sort rate --save /etc/pacman.d/mirrorlist
# When:       2021-06-10 10:27:06 UTC
# From:       https://www.archlinux.org/mirrors/status/json/
# Retrieved:  2021-06-10 10:26:49 UTC
# Last Check: 2021-06-10 09:15:02 UTC

Server = http://mirrors.piconets.webwerks.in/archlinux-mirror/$repo/os/$arch
Server = https://mirrors.piconets.webwerks.in/archlinux-mirror/$repo/os/$arch
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch

残念ながら、インドで利用できるArchLinuxミラーは3つだけです。

2.5。複数の国からミラーリストを取得する

以下のように、カンマで区切って複数の国を指定することもできます。

$ sudo reflector --country 'United States,India' -l 10 --age 12 --protocol https --sort rate --save /etc/pacman.d/mirrorlist 

このコマンドは、上位の10個のHTTPSミラーを選択します 過去12時間以内に同期 米国のいずれかにあります またはインド 、ダウンロード速度で並べ替え、ファイル/etc/pacman.d/mirrorlistを上書きします ファイル。

2.6。国別のミラーリストを取得する

国でソートされたすべてのリストを取得するには、次のコマンドを実行します。

$ sudo curl -o /etc/pacman.d/mirrorlist https://archlinux.org/mirrorlist/all/

国別のミラーを取得したら、/etc/pacman.d/mirrorlistを編集します ファイル:

$ sudo nano /etc/pacman.d/mirrorlist

選択したミラーURLのコメントを解除して、有効にします。

たとえば、インドのミラーを有効にしました。そこで、各URLの前にある(#)記号を削除しました。

[...]
India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
Server = http://mirrors.piconets.webwerks.in/archlinux-mirror/$repo/os/$arch
Server = https://mirrors.piconets.webwerks.in/archlinux-mirror/$repo/os/$arch
[...]

ファイルを保存して閉じます。コマンドを使用してリポジトリリストを更新します:

$ sudo pacman -Syu

2.7。最速のミラーを選択

Reflectorは、ArchLinux用の最速のミラーを取得できます。

次のコマンドは、5つの最速の10個のHTTPSミラーを取得します 米国にあります 、ダウンロード速度で並べ替え、ファイル/etc/pacman.d/mirrorlistを上書きします ファイル。

$ sudo reflector -f 5 --country 'United States' --protocol https --sort rate --save /etc/pacman.d/mirrorlist 

2.8。プロトコルを指定する

httpsなど、特定のタイプのプロトコルをサポートする最新のミラーを選択できます。 、httpftp など

たとえば、このコマンドは 5を選択します 米国の最新のミラー HTTPをサポートする /etc/pacman.d/mirrorlistをオーバーライドします ファイル:

$ sudo reflector --latest 5 --protocol http --country 'United States' --save /etc/pacman.d/mirrorlist

サポートされている他のオプションは--isosです。 ISOをホストするミラーのみを返します--ipv4 IPv4と--ipv6をサポートするミラーのみを返します IPv6をサポートするミラーのみを返します。

3。起動時にArchLinuxミラーリストを自動的に更新する

リフレクターにはsystemdが含まれています Pacmanのミラーリストを自動的に更新するために使用できるサービスユニットとタイマーユニット。

3.1。リフレクターsystemdサービスを有効にして開始します

バージョン2020.8以降、Reflectorにはreflector.serviceが付属しています。 。再起動するたびにArchLinuxミラーリストを自動的に更新するには、次のコマンドを使用してこのサービスを有効にして開始します。

$ sudo systemctl enable reflector.service
$ sudo systemctl start reflector.service

reflection.serviceは、/etc/xdg/reflector/reflector.confで指定されたパラメーターを使用してreflectorを実行します ファイル。

ほとんどの場合、デフォルト設定で十分です。これがreflector.confの内容です ファイル:

$ cat /etc/xdg/reflector/reflector.conf

出力例:

#
# Empty lines and lines beginning with "#" are ignored.  All other lines should
# contain valid reflector command-line arguments. The lines are parsed with
# Python's shlex modules so standard shell syntax should work. All arguments are
# collected into a single argument list.
#
# See "reflector --help" for details.

# Recommended Options

# Set the output path where the mirrorlist will be saved (--save).
--save /etc/pacman.d/mirrorlist

# Select the transfer protocol (--protocol).
--protocol https

# Select the country (--country).
# Consult the list of available countries with "reflector --list-countries" and
# select the countries nearest to you or the ones that you trust. For example:
# --country France,Germany

# Use only the  most recently synchronized mirrors (--latest).
--latest 5

# Sort the mirrors by synchronization time (--sort).
--sort age

このファイルを編集して、要件に応じてパラメーターを変更することもできます。このファイルは、すべてのリフレクターコマンドライン引数を受け入れます。

オプションの空白行と#で始まるコメント行を使用して、引数を1行にまとめたり、複数の行に分割したりできます。 。

3.2。リフレクターsystemdタイマーを有効にして開始します

リフレクターはreflector.timerという名前の別のsystemdユニットを出荷します 、reflector.serviceを開始します 毎週。

システムの起動時に自動的に有効にして起動するには、次のコマンドを1つずつ実行します。

$ sudo systemctl enable reflector.timer
$ sudo systemctl start reflector.timer

デフォルトでは、reflector.serviceが開始されます 週に一度。スケジュールされた時間を待ちたくない場合は、reflector.serviceを開始して、pacmanのミラーリストをすぐに更新できます。

$ sudo systemctl start reflector.service

結論

このガイドでは、Reflectorとは何か、Reflectorスクリプトを使用してArch Linuxシステムの最新のPacmanミラーリストを取得する方法、そして最後にArchLinuxミラーリストを自動的に更新する方法を学びました。


Arch Linux
  1. ArchLinuxでSFTPサーバーをセットアップする方法

  2. LinuxまたはMacOSXでSSHを使用してサーバーに接続します

  3. Linux/Unix サーバーで開いているポートを一覧表示する方法

  1. Linux でソケットを使用して https リクエストを行う

  2. Arch Linux 上の VPN サーバー

  3. Arch Linux はサーバー環境に適していますか?

  1. Chronyを使用してLinuxサーバーで時刻を同期する方法

  2. Linux VPSでCS:GOサーバーを作成する方法

  3. ArchLinuxをサーバーとしてインストールおよび設定する方法