该文档在CentOS7.6系统下进行操作系统的初始化配置以及docker环境,为之后的Kubernetes环境配置提供基础依赖
主机名称 | ip地址 | 操作系统 | 角色 | 软件版本 | 备注 |
---|---|---|---|---|---|
opsharbor-shqs-1 | 10.99.73.38 | CentOS 7.6 | docker宿主机 |
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
swap不关闭kubelet可能会出错,如果不关闭也可以修改kubelet的配置
# 我使用的是KVM虚拟机,本身就没有使用swap空间,这里记录下设置方式[来自网络文章]
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
# 我使用的虚拟机模板配置了很多内核参数,这里就不列出来了,只关心相关的。
yum install bridge-utils -y
modprobe br_netfilter
cat <<EOF > /etc/sysctl.d/container.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# 使配置生效
sysctl --system
# 设置ulimit,根据需要设置,这里验证环境如此设置足够了。
cat <<EOF > /etc/security/limits.d/90-nproc.conf
* soft nproc 20480
* hard nproc 20480
* soft nofile 102400
* hard nofile 102400
root soft nproc unlimited
EOF
# 在节点执行
hostnamectl set-hostname opsharbor-shqs-1
# 添加解析记录(这里使用cat命令展示设置后的内容)
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.99.73.38 opsharbor-shqs-1
设置自己的时钟源,采用默认公共的也可以
# master 配置
vi /etc/chrony.conf
...
server 10.99.73.5 iburst
server 10.99.73.6 iburst
# 启动chronyd
systemctl enable chronyd.service
systemctl restart chronyd.service
yum -y install epel-release
yum -y update
# 更新完成后重启操作系统
reboot
# 我使用的虚拟机模版默认已经配置了很多系统工具,这里是从文档查阅需要的。
yum -y install yum-utils device-mapper-persistent-data lvm2 conntrack-tools bridge-utils ipvsadm
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 查看docker-ce版本列表
yum list docker-ce --showduplicates|sort -r
docker-ce.x86_64 3:19.03.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.11-3.el7 docker-ce-stable ## 用这个版本(当前最新版本)
docker-ce.x86_64 3:19.03.10-3.el7 docker-ce-stable
docker-ce.x86_64 3:19.03.0-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.9-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.8-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.7-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.6-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.5-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.4-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.3-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
yum -y install docker-ce-19.03.11
#会自动安装依赖docker-ce-cli containerd.io
yum -y install yum-plugin-versionlock
yum versionlock docker-ce
yum versionlock list
Loaded plugins: fastestmirror, priorities, versionlock
3:docker-ce-19.03.11-3.el7.*
versionlock list done
systemctl enable docker.service
systemctl start docker.service
# docker version
Client: Docker Engine - Community
Version: 19.03.11
API version: 1.40
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:13:48 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.11
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:12:26 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
# docker images
null
# docker run hello-worlddocke
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest bf756fb1ae65 5 months ago 13.3kB
----------------到这里就结束了,下面的配置是使用自签证书的私有仓库(https)的配置----------------
docker使用自签证书的私有仓库需要配置自签证书根证书到docker环境,使用openssl配置自签证书的方式有所不同,这里使用的方式参考 配置企业级镜像仓库Harbor 生成自签证书相关内容。
docker环境配置使用自签证书的方式有多种。这里列出2中方式
私有仓库地址 | 自签证书 |
---|---|
https://csrepo.ejuops.com | csrepo.ejuops.com.crt |
certs]# ll
-rw-r--r-- 1 root root 1212 Jun 19 10:40 csrepo.ejuops.com.crt #这个就是我们需要的证书文件
-rw-r--r-- 1 root root 1009 Jun 19 10:40 csrepo.ejuops.com.csr
-rw-r--r-- 1 root root 1675 Jun 19 10:40 csrepo.ejuops.com.key
-rw-r--r-- 1 root root 1743 Jun 19 10:40 csrepo.ejuops.com.pass.key
# 安装ca-certificates
yum -y install ca-certificates
# 证书文件放入 /usr/share/pki/ca-trust-source/anchors
cp csrepo.ejuops.com.crt /usr/share/pki/ca-trust-source/anchors/
# 更细系统支持证书列表
update-ca-trust
# 查看是否更细追加成功
tail -n23 /etc/ssl/certs/ca-bundle.trust.crt
# csrepo.ejuops.com #看到这一行说明更新成功了
-----BEGIN TRUSTED CERTIFICATE-----
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [这里是省略的意思]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
-----END TRUSTED CERTIFICATE-----
#如果docker守护进程已经启动,需要重启下docker守护进程
systemctl restart docker
# 验证
docker pull csrepo.ejuops.com/library/hello-world:latest
latest: Pulling from library/hello-world
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Image is up to date for csrepo.ejuops.com/library/hello-world:latest
csrepo.ejuops.com/library/hello-world:latest
以上说明配置成功了。
这里测试的私有仓库域名是: csrepo.ejuops.com
# 配置
DOCKER_REGISTRY=csrepo.ejuops.com
mkdir -p /etc/docker/certs.d/${DOCKER_REGISTRY}
cp ${DOCKER_REGISTRY}.crt /etc/docker/certs.d/${DOCKER_REGISTRY}/ca.crt
#验证,这种方式docker守护进程不需要重启
docker pull csrepo.ejuops.com/library/hello-world:latest
latest: Pulling from library/hello-world
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Image is up to date for csrepo.ejuops.com/library/hello-world:latest
csrepo.ejuops.com/library/hello-world:latest