CentOS 7同期リモートミラーローカルyumサーバの構築
8990 ワード
CentOS 7同期リモートミラーローカルyumサーバの構築
CentOSミラーサイトのデータをローカルサーバに同期し、nginxを使用してhttpサービスを実現し、ローカルエリアネットワーク内の他の機器にyumサービスを提供し、イントラネットyumインストールソフトウェアの問題を解決する.
一、前提条件:
1、本機はインターネットに接続し、CentOSミラーサイトに正常にアクセスでき、本例は中科大学のソースを使用する:mirrors.ustc.edu.cn.
2、CentOSミラーサイトはrsyncプロトコルをサポートする必要がある.
二、構築過程:
1、本機のインストールに必要なツール:
2、ディレクトリの作成(場所の自由):
(1)、centos倉庫ディレクトリ、centosplusは同期せず、一般的には使用できません.
(2)、epel倉庫目次:
3、リモートミラーの同期(外部ネットワーク帯域幅に関係する):
4、ローカル倉庫メタデータ及びインデックスの生成
5、同期スクリプト.サーバーが外部ネットワークに接続されている場合、定期的にリモートミラーと同期を保つようにスケジュールタスクに設定できます.
6、selinuxを閉じる:
7、nginxのインストールと配置(cenos公式ソースにはnginxが含まれておらず、epelソースでnginxをインストール):
(1)、epelソースのインストール:
(2)、nginxのインストール:
(3)、nginxを起動する:
(4)、電源を入れて自動的にnginxサービスを起動する:
(5)、ファイアウォールはnginxサービスを許可する:
(6)、/etc/nginx/conf.d/の下にrepos.confプロファイルを作成します.
(7)、変更/etc/nginx/nginx.confは、nginxのデフォルトの80ポートサービスを注釈します.
(8)、nginxサービスを再起動するか、nginxに構成を再ロードさせる:
http://{ipaddress}でコンテンツが表示されるようになりましたが、403などのエラーが報告された場合はnginx関連エラーの解決策を探してください.
三、yumクライアントの構成:
1、修正/etc/yum.repos.d/CentOS-Base.repoファイルの各倉庫のbaseurlとgpgkey構成項目は、テンプレートの{ipaddress}が実際のIPアドレスに置き換えられます.
2、修理1の方式と/etc/yumを修正する.repos.d/epel.repoプロファイル、ない場合は次のようなプロファイルを作成します.
3、yumキャッシュをクリアする:
4、yumキャッシュディレクトリを削除する:
5、yumキャッシュを作成する:
構成終了!!!
CentOSミラーサイトのデータをローカルサーバに同期し、nginxを使用してhttpサービスを実現し、ローカルエリアネットワーク内の他の機器にyumサービスを提供し、イントラネットyumインストールソフトウェアの問題を解決する.
一、前提条件:
1、本機はインターネットに接続し、CentOSミラーサイトに正常にアクセスでき、本例は中科大学のソースを使用する:mirrors.ustc.edu.cn.
2、CentOSミラーサイトはrsyncプロトコルをサポートする必要がある.
二、構築過程:
1、本機のインストールに必要なツール:
yum -y install rsync createrepo
2、ディレクトリの作成(場所の自由):
(1)、centos倉庫ディレクトリ、centosplusは同期せず、一般的には使用できません.
mkdir -p /storage/repos/centos/7/{os,updates,extras,centosplus}/x86_64
(2)、epel倉庫目次:
mkdir -p /storage/repos/epel/7/x86_64
# EPEL ,
mkdir -p /storage/repos/epel/7/SRPMS/
3、リモートミラーの同期(外部ネットワーク帯域幅に関係する):
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/os/x86_64/ /storage/repos/centos/7/os/x86_64/
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/updates/x86_64/ /storage/repos/centos/7/updates/x86_64/
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/extras/x86_64/ /storage/repos/centos/7/extras/x86_64/
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/7/centosplus/x86_64/ /storage/repos/centos/7/centosplus/x86_64/
# gpgkey
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /storage/repos/centos/
4、ローカル倉庫メタデータ及びインデックスの生成
createrepo /storage/repos/centos/7/os/x86_64/
createrepo /storage/repos/centos/7/updates/x86_64/
createrepo /storage/repos/centos/7/extras/x86_64/
createrepo /storage/repos/centos/7/centosplus/x86_64/
5、同期スクリプト.サーバーが外部ネットワークに接続されている場合、定期的にリモートミラーと同期を保つようにスケジュールタスクに設定できます.
vi /etc/cron.daily/update-repos
# create new
#!/bin/bash
VER='7'
ARCH='x86_64'
CENTOS_REPOS=(os updates extras centosplus)
# centos
for REPO in ${CENTOS_REPOS[@]}
do
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/${VER}/${CENTOS_REPOS}/${ARCH}/ /storage/repos/centos/${VER}/${CENTOS_REPOS}/${ARCH}/
createrepo /storage/repos/centos/${VER}/${CENTOS_REPOS}/${ARCH}/
done
# gpgkey
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7 /storage/repos/centos/
# epel
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/7/x86_64/ /storage/repos/epel/7/x86_64/
createrepo /storage/repos/epel/7/x86_64/
# epel , epel
#rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/7/SRPMS/ /storage/repos/epel/7/SRPMS/
#createrepo /storage/repos/epel/7/SRPMS/
# gpgkey
rsync -avz --delete --exclude='repodata' rsync://mirrors.ustc.edu.cn/epel/RPM-GPG-KEY-EPEL-7 /storage/repos/epel/
# wq ,
# chmod 755 /etc/cron.daily/update-repo
6、selinuxを閉じる:
# 1、
vi /etc/selinux/config
# SELINUX=enforcing : SELINUX=disabled
# 2、
setenforce 0
7、nginxのインストールと配置(cenos公式ソースにはnginxが含まれておらず、epelソースでnginxをインストール):
(1)、epelソースのインストール:
yum install epel-release
(2)、nginxのインストール:
yum install -y nginx
(3)、nginxを起動する:
systemctl start nginx.service
(4)、電源を入れて自動的にnginxサービスを起動する:
systemctl enable nginx.service
(5)、ファイアウォールはnginxサービスを許可する:
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
(6)、/etc/nginx/conf.d/の下にrepos.confプロファイルを作成します.
vim /etc/nginx/conf.d/repos.conf
server {
listen 80;
server_name _;
# 404
error_page 404 /404.html;
# 50x
error_page 500 503 504 /50x.html;
error_log /var/log/nginx/repos_error.log;
access_log /var/log/nginx/repos_access.log;
root /storage/repos/;
location / {
autoindex on;
}
location = /50x.html {
root /usr/share/nginx/html;
}
location = /404.html {
root /usr/share/nginx/html;
}
}
(7)、変更/etc/nginx/nginx.confは、nginxのデフォルトの80ポートサービスを注釈します.
# server {
# listen 80 default_server;
# listen [::]:80 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
# location / {
# }
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
(8)、nginxサービスを再起動するか、nginxに構成を再ロードさせる:
systemctl restart nginx.service
#
systemctl reload nginx.service
http://{ipaddress}でコンテンツが表示されるようになりましたが、403などのエラーが報告された場合はnginx関連エラーの解決策を探してください.
三、yumクライアントの構成:
1、修正/etc/yum.repos.d/CentOS-Base.repoファイルの各倉庫のbaseurlとgpgkey構成項目は、テンプレートの{ipaddress}が実際のIPアドレスに置き換えられます.
# 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&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://{ipaddress}/centos/$releasever/os/$basearch/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://{ipaddress}/centos/$releasever/updates/$basearch/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://{ipaddress}/centos/$releasever/extras/$basearch/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://{ipaddress}/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
gpgkey=http://{ipaddress}/centos/RPM-GPG-KEY-CentOS-7
2、修理1の方式と/etc/yumを修正する.repos.d/epel.repoプロファイル、ない場合は次のようなプロファイルを作成します.
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
baseurl=http://{ipaddress}//epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
baseurl=http://{ipaddress}/epel/7/$basearch/debug
failovermethod=priority
enabled=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7
gpgcheck=1
#[epel-source] # SRPMS ,
#name=Extra Packages for Enterprise Linux 7 - $basearch - Source
##baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
#failovermethod=priority
#enabled=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
#gpgkey=http://{ipaddress}/epel/RPM-GPG-KEY-EPEL-7
#gpgcheck=1
3、yumキャッシュをクリアする:
yum clean all
4、yumキャッシュディレクトリを削除する:
rm -rf /var/cache/yum/*
5、yumキャッシュを作成する:
yum makecache
構成終了!!!