รับทําเว็บไซต์ รับทําseo
บทความที่น่าสนใจ

บทความ ที่น่าสนใจ

Linux Server (CentOS) : เปลี่ยนคอนฟิก yum ให้มาใช้ repos ในไทย

    หากต้องการใช้ yum ติดตั้งโปรแกรมเพิ่มเติม หรือปรับปรุงโปรแกรมเป็นเวอร์ชั่นใหม่ เราต้องใช้ repos ที่อยู่บนอินเตอร์เน็ต

    ดีฟอลต์จากการติดตั้ง CentOS 6.2 จะมีคอนฟิก repos ติดตั้งมาด้วย โดยจะชี้ไปยังเว็บไซต์ mirrorlist.centos.org แสดงรายชื่อเว็บไซต์ repos ที่ให้บริการดาวน์โหลดไฟล์ rpm อีกที

    แต่ข้อเสียของการใช้คอนฟิก repos แบบดีฟอลต์นี้ ในบางครั้งเราอาจต้องไปดาวน์โหลดไฟล์จากเว็บไซต์ที่อยู่ต่างประเทศ ทำให้ความเร็วที่ได้ค่อนข้างช้า

    ในบทนี้ขอแนะนำวิธีเปลี่ยนคอนฟิก repos ของ yum ให้ชี้มายังเว็บไซต์ในประเทศไทย

    ตัวอย่างคอนฟิกไฟล์ CentOS-Base.repo ซึ่งเก็บคอนฟิก repos ชื่อ  base, extras, updates

    [root@cent62-yum ~]# cat /etc/yum.repos.d/CentOS-Base.repo # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client.  You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # #  [base] name=CentOS-$releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ ...

    จากคอนฟิก repos ชื่อ “base”  จะดึงข้อมูลชื่อเว็บไซต์ที่คอนฟิกไว้ในออปชั่น “mirrorlist” แต่ตอนใช้งานจริงจะต้องแทนค่าตัวแปร

    ใช้คำสั่ง yum-config-manager ตามด้วยชื่อ repos เพื่อแสดงคอนฟิก “base” ผลลัพธ์จะมีการแทนที่ค่าตัวแปรที่ ($) ที่เขียนไว้ในไฟล์คอนฟิก

    [root@cent62-yum ~]# yum-config-manager base Loaded plugins: fastestmirror ========================= repo: base ========================= [base] bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/6 baseurl = ... mirrorlist = http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os mirrorlist_expire = 86400 name = CentOS-6 - Base ...

    ใช้คำสั่ง curl เพื่อดึงข้อมูลจากเว็บไซต์ที่ระบุไว้ใน “mirrorlist” จะได้รายชื่อเว็บไซต์ที่ใช้เป็น repos ได้

    [root@cent62-yum ~]# curl 'http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os'  http://mirrors.psu.ac.th/pub/centos/6.2/os/x86_64/  http://mirror.issp.co.th/centos/6.2/os/x86_64/  http://mirror1.ku.ac.th/centos/6.2/os/x86_64/  http://mirror.yourconnect.com/centos/6.2/os/x86_64/  http://mirrors.btte.net/centos/6.2/os/x86_64/  ...

    ผลลัพธ์ที่ได้จะเปลี่ยนไปเรื่อยๆ

    รันคำสั่ง yum repolist เพื่อดูข้อมูล repos ที่จะใช้ หากรันครั้งแรก จะมีการดึงข้อมูล repos ใหม่จากอินเตอร์เน็ต หากเป็นการรันครั้งต่อๆ ไป จะใช้ข้อมูลที่เก็บไว้ในเครื่องแทน (cache)

    [root@cent62-yum ~]# yum repolist Loaded plugins: fastestmirror, security Determining fastest mirrors  * base: mirrors.btte.net  * extras: mirrors.btte.net  * updates: mirrors.btte.net base                                                     | 3.7 kB     00:00 base/primary_db                                          | 4.5 MB     00:23 extras                                                   | 3.5 kB     00:00 extras/primary_db                                        | 6.3 kB     00:00 updates                                                  | 3.5 kB     00:00 updates/primary_db                                       | 3.0 MB     00:10 repo id                        repo name                                  status base                           CentOS-6 - Base                            6,294 extras                         CentOS-6 - Extras                              4 updates                        CentOS-6 - Updates                           832 repolist: 7,130

    ปัญหาหากใช้คอนฟิกดีฟอลต์แบบนี้อย่างที่กล่าวไว้ตอนแรก เราไม่สามารถควบคุมได้ว่าจะได้ใช้ repos จากเว็บไซต์ไหน เช่นจากตัวอย่างที่รัน เป็นเว็บไซต์จากประเทศจีน

    เปลี่ยนมาใช้ repos ในไทย

    เพื่อความเร็วในการดาวน์โหลดไฟล์ แนะนำให้ใช้ repos จากเว็บไซต์ในเมืองไทย ดูง่ายๆ ชื่อโดเมนของเว็บไซต์ลงท้ายด้วย .th จากผลลัพธ์ของคำสั่ง curl จะมี

      - http://mirrors.psu.ac.th/pub/centos/6.2/os/x86_64/

      - http://mirror.issp.co.th/centos/6.2/os/x86_64/

      - http://mirror1.ku.ac.th/centos/6.2/os/x86_64/

    การเปลี่ยนคอนฟิก repos ให้มาใช้เว็บไซต์ที่ต้องการ ทำได้โดยแก้ไขไฟล์ repo ปิดคอนฟิก mirrorlist  แล้วตั้งค่าเว็บไซต์ในคอนฟิก baseurl

    เช่นต้องการเปลี่ยน repos ชื่อ base, extras, updates ให้ชี้ไปยัง mirrors.psu.ac.th ทำได้โดยแก้ไขไฟล์ CentOS-Base.repo

    สังเกตการแก้ไขคอนฟิก baseurl ในแต่ละ repos จะไม่เหมือนกัน และจะใช้ชื่อตัวแปร ($) แทนการระบุชื่อเวอร์ชั่น  ห้ามระุบุเป็น 6.2 เพราะเมื่อเวอร์ชั่นใหม่ออกมาแล้ว จะทำให้ไฟล์คอนฟิก repos นี้ใช้งานไม่ได้

    [root@cent62-yum ~]# cat /etc/yum.repos.d/CentOS-Base.repo
    ...
    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    baseurl=http://mirrors.psu.ac.th/pub/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled = 1

    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
    baseurl=http://mirrors.psu.ac.th/pub/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled = 1

    #additional packages that may be useful
    [extras] name=CentOS-$releasever - Extras
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    baseurl=http://mirrors.psu.ac.th/pub/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
    enabled = 1

    ใช้คำสั่ง yum repolist โดยเพิ่มออปชั่น ‘-v’ เพื่อดูข้อมูลเพิ่มเติมของแต่ละ repos

    [root@cent62-yum ~]# yum -v repolist Loading "fastestmirror" plugin Loading "security" plugin Config time: 0.044 Yum Version: 3.2.29 Loading mirror speeds from cached hostfile Setting up Package Sacks pkgsack time: 0.073 Repo-id      : base Repo-name    : CentOS-6 - Base Repo-revision: 1324003045 Repo-updated : Fri Dec 16 09:38:07 2011 Repo-pkgs    : 6,294 Repo-size    : 5.1 G Repo-baseurl : http://mirrors.psu.ac.th/pub/centos/6/os/x86_64/ Repo-expire  : 21,600 second(s) (last: Mon May  7 13:16:01 2012)  Repo-id      : extras Repo-name    : CentOS-6 - Extras Repo-revision: 1327502687 Repo-updated : Wed Jan 25 21:44:47 2012 Repo-pkgs    : 4 Repo-size    : 3.0 M Repo-baseurl : http://mirrors.psu.ac.th/pub/centos/6/extras/x86_64/ Repo-expire  : 21,600 second(s) (last: Mon May  7 13:16:02 2012)  Repo-id      : updates Repo-name    : CentOS-6 - Updates Repo-revision: 1336165833 Repo-updated : Sat May  5 04:31:48 2012 Repo-pkgs    : 832 Repo-size    : 1.7 G Repo-baseurl : http://mirrors.psu.ac.th/pub/centos/6/updates/x86_64/ Repo-expire  : 21,600 second(s) (last: Mon May  7 13:16:02 2012)  repolist: 7,130

    หลังจากเปลี่ยนแล้ว ตอนนี้ yum จะดาวน์โหลดไฟล์จาก repos ตามเว็บไซต์ที่เราระบุใน baseurl แทน

     

บทความที่น่าสนใจ

บทความ ล่าสุด

บทความ ความรู้ด้านไอที, คอมพิวเตอร์ Techonlogy, Gadget, ความรู้เกี่ยวกับคอมพิวเตอร์ กับทาง SoftMelt.com