For customer local deployment on centos or other linux system, the client have not internet access, you need a local yum repository or you just want use your own instead of public rpms.

There are two way to build a local yum mirror, both of them uses createrepo command.

  • Access local rpm
  • Access LAN yum server

The local rpm way introduced in this article, with k8s installation guide.

At this time, I will introduce a LAN yum server which sync with internet repo, and provides service for local server without internet access privelige.

Yum mirror server:

# 1. Network access
sudo yum install httpd -y
# 2. Install createrepo 
sudo yum install createrepo -y
# 3. Install repo management tool
sudo yum install yum-utils -y
# 4. Create folder to store rpms
sudo mkdir –p /var/www/html/repos
sudo mkdir –p /var/www/html/repos/{base,centosplus,extras,updates}

Now, you can sync repo, it will cosume lots of disk storage:

sudo reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/repos/

All you need to do is just wait... for completed.

Create meta info for repo:

createrepo -d -s sha1 /var/www/html

You can use createrepo multi times for docker, kubernetes repos, Run yum clean all in client when your add new repos

For more createrepo command details

Start httpd server, disable firewall(Or firewall rule if you want)

systemctl enable httpd
systemctl start httpd
systemctl disable firewalld
systemctl stop firewalld

Yum local client:

After server is ready, setup client for test

mv /etc/yum.repos.d/*.repo /tmp/
sudo vi /etc/yum.repos.d/remote.repo
[remote]
name=RHEL Apache
baseurl=http://192.168.126.143
enabled=1
gpgcheck=0

Test it:

sudo yum install httpd -y

Config mirror for server

If your yum server repo sync is slow, you might want to switch to another mirror, here is my configuration.

# CentOS-Base
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup -y
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# epel
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup -y
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup -y
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -y
# kubernetes
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Install kubeadm

# setenforce 0
# yum install -y kubelet kubeadm kubectl
# systemctl enable kubelet && systemctl start kubelet
# yum install -y --nogpgcheck kubelet kubeadm kubectl

Aliyun mirrors:

阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区
阿里巴巴开源镜像站,免费提供Linux镜像下载服务,拥有Ubuntu、CentOS、Deepin、MongoDB、Apache、Maven、Composer等多种开源软件镜像源,此外还提供域名解析DNS、网络授时NTP等服务,致力于为互联网用户提供全面,高效和稳定的基础服务。