Skip to content

Instantly share code, notes, and snippets.

@markruler
Last active July 31, 2024 03:45
Show Gist options
  • Save markruler/738709aad9ed53fd56b6d07d7a7e5916 to your computer and use it in GitHub Desktop.
Save markruler/738709aad9ed53fd56b6d07d7a7e5916 to your computer and use it in GitHub Desktop.
Mirror a repository in RHEL

Local Mirror of RHEL

server 1

yum install yum-utils createrepo
# bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
whereis python
# python: /usr/bin/python3.6m /usr/bin/python3.6 /usr/lib/python2.7 /usr/lib/python3.6 /usr/lib64/python2.7 /usr/lib64/python3.6 /etc/python /usr/local/lib/python3.6 /usr/include/python2.7 /usr/include/python3.6m
whereis yum
# yum: /usr/bin/yum /etc/yum /etc/yum.conf /usr/share/man/man8/yum.8
vi /usr/bin/yum
#!/usr/bin/python -> #!/usr/bin/python2.7
# python3.x는 syntax error
  • origin yum repo
[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/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[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/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[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/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[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/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# docker-ce.repo
[docker-ce]
name=Docker-CE Repository
baseurl=https://download.docker.com/linux/centos/7/$basearch/stable
enabled=1
gpgcheck=1
keepcache=0
gpgkey=https://download.docker.com/linux/centos/gpg
# kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
yum update
yum repolist

# Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
# repo id                           repo name                             status
# !base/7/x86_64                    CentOS-7 - Base                       10,072
# !extras/7/x86_64                  CentOS-7 - Extras                        448
# !updates/7/x86_64                 CentOS-7 - Updates                       773
# !docker-ce/x86_64                 Docker-CE Repository                      82
# !kubernetes                       Kubernetes                               588
# repolist: 11,963m

mkdir -p /var/markruler

reposync --gpgcheck -l --repoid=base --download_path=/var/markruler --downloadcom
reposync --gpgcheck -l --repoid=extras --download_path=/var/markruler --downloadcom
reposync --gpgcheck -l --repoid=updates --download_path=/var/markruler --downloadcom
reposync --gpgcheck -l --repoid=docker-ce --download_path=/var/markruler --downloadcom
reposync --gpgcheck -l --repoid=kubernetes --download_path=/var/markruler --downloadcom

ls -hal /var/markruler
# base docker-ce extras kubernetes updates
  • Setting Proxy Server
yum install -y httpd

# 서버 부팅시 아파치 자동으로 올라오게 설정
# 1번째 방법
systemctl enable httpd

# 2번째 방법
chkconfig httpd
# disabled
chkconfig httpd on
# Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
chkconfig httpd
# enabled

# 데몬 시작
systemctl start httpd

# repository 디렉터리를 아파치 document root에 심볼릭 링크
ln -s /var/markruler /var/www/html/repo -v
createrepo -v /var/markruler/base
createrepo -v /var/markruler/extras
createrepo -v /var/markruler/updates
createrepo -v /var/markruler/docker-ce
createrepo -v /var/markruler/kubernetes
  • CentOS 8
# The createrepo command is not needed anymore because reposync downloads everything, including the repodata.
reposync -p <download-path> --download-metadata --repo=<repo id>
# 1번째 방법. SELINUX=permissive
setenforce 0
sestatus # Current mode: permissive
# Permissive mode 는 rule 에 어긋나는 동작이 있을 경우 audit log 를 남기고 해당 operation 은 허용된다.
# 개발 서버일 경우 특정 daemon 이나 서비스에 문제가 있을 경우 setenforce 0 으로 Permissive mode 로 전환하여 문제 해결후 enforce mode 로 전환하는걸 추천한다. (setenforce 1)

# 2번째 방법. SELINUX=disable
# vi /etc/sysconfig/selinux -> /etc/selinux/config: SELINUX=disabled
# 인터넷에 연결된 리눅스 서버라면 SELinux 해제는 결코 추천하지 않는다.
# 해제할 경우 다시 활성화 시키려면 재부팅이 필요하며 재부팅시 모든 자원에 대해 보안 레이블을 설정해야 하므로 부팅 시간이 매우 오래 걸릴 수 있다.
# disable firewall
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld

server 2

  • vi /etc/yum.repos.d/markruler.repo
[base]
name=CentOS-$releasever - Base
# baseurl=http://192.168.213.4/repo/$releasever/os/$basearch/
baseurl=http://192.168.213.4/repo/os/
enabled=1
keepcache=0
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates
# baseurl=http://192.168.213.4/repo/$releasever/updates/$basearch/
baseurl=http://192.168.213.4/repo/updates/
enabled=1
keepcache=0
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras
# baseurl=http://192.168.213.4/repo/$releasever/extras/$basearch/
baseurl=http://192.168.213.4/repo/extras/
enabled=1
keepcache=0
gpgcheck=0

[centosplus]
name=CentOS-$releasever - Plus
# baseurl=http://192.168.213.4/repo/$releasever/plus/$basearch/
baseurl=http://192.168.213.4/repo/plus/
enabled=1
keepcache=0
gpgcheck=0

[docker-ce]
name=Docker-CE Repository
# baseurl=http://192.168.213.4/repo/$releasever/docker-ce/$basearch/
baseurl=http://192.168.213.4/repo/docker-ce/
enabled=1
keepcache=0
gpgcheck=0

[kubernetes]
name=Kubernetes
# baseurl=http://192.168.213.4/repo/$releasever/kubernetes/$basearch/
baseurl=http://192.168.213.4/repo/kubernetes/
enabled=1
keepcache=0
gpgcheck=0
curl -LO http://192.168.213.4/repo/docker-ce/Packages/docker-ce-20.10.0-3.el7.x86_64.rpm
# or
wget http://192.168.213.4/repo/docker-ce/Packages/docker-ce-20.10.0-3.el7.x86_64.rpm
# or
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-<VERSION_STRING>
  • 404 error
yum clean all
rm -rf /var/cache/yum/*
yum update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment