挂载,升级系统内核,并设置开启自启
[root@192 ~]# hostnamectl set-hostname harbor '//修改主机名'
[root@192 ~]# su
[root@harbor ~]# mount.cifs //192.168.11.1/ccc /mnt '//挂载宿主机'
Password for root@//192.168.11.1/ccc:
[root@harbor ~]# cd /mnt/kubernetes/
[root@harbor kubernetes]# ls
elrepo-release-7.0-3.el7.elrepo.noarch.rpm kube-flannel.yml
kubeadm-basic.images.tar.gz
[root@harbor kubernetes]# rpm -ivh elrepo-release-7.0-3.el7.elrepo.noarch.rpm '//安装内核rpm包'
[root@harbor kubernetes]# yum --enablerepo=elrepo-kernel install -y kernel-lt '//安装内核相关组件'
[root@harbor kubernetes]# grub2-set-default "CentOS Linux (4.4.213-1.el7.elrepo.x86_64) 7 (Core)" '//设置4.4内核开机自启'
[root@harbor kubernetes]# init 6
安装docker并设置开启自启
[root@harbor ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 '//安装docker依赖'
[root@harbor ~]# yum-config-manager \
> --add-repo \
> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo '//加载阿里云docker镜像,yum仓库'
[root@harbor ~]# yum update -y && yum install -y docker-ce '//更新并安装docker:时间较长'
[root@harbor ~]# grub2-set-default "CentOS Linux (4.4.213-1.el7.elrepo.x86_64) 7 (Core)"
[root@harbor ~]# init 6
[root@harbor ~]# systemctl start docker '//开启docker'
[root@harbor ~]# cat > /etc/docker/daemon.json < {
> "exec-opts": ["native.cgroupdriver=systemd"],
> "log-driver": "json-file",
> "log-opts": {
> "max-size": "100m"
> }
> }
> EOF '//配置dockerdaemon'
[root@harbor ~]# mkdir ‐p /etc/systemd/system/docker.service.d
[root@harbor ~]# systemctl daemon-reload && systemctl restart docker && systemctl enable docker
证书
[root@harbor ~]# vim /etc/docker/daemon.json '//harbor和k8s主从节点都要做'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
}, '//注意逗号'
"insecure-registries": ["https://hub.atguigu.com"] '//添加了局域网证书地址,镜像仓库地址'
}
[root@harbor ~]# systemctl restart docker '//主从节点重启docker服务'
配置docker-compose并解压harbor软件包
[root@harbor ~]# mount.cifs //192.168.11.1/ccc /mnt '//挂载宿主机'
Password for root@//192.168.11.1/ccc:
[root@harbor ~]# cd /mnt/kubernetes/
[root@harbor kubernetes]# mv docker-compose /usr/local/bin/ '//移动docker-compose'
[root@harbor kubernetes]# chmod a+x /usr/local/bin/docker-compose '//给权限'
[root@harbor kubernetes]# tar zxvf harbor-offline-installer-v1.2.0.tgz -C /usr/local '//解压harbor软件包'
[root@harbor kubernetes]# cd /usr/local/harbor/
[root@harbor harbor]# vim harbor.cfg '//编辑配置文件'
hostname = hub.atguigu.com '//修改主机名'
ui_url_protocol = https '//协议修改为https'
创建https证书以及配置相关目录权限
[root@harbor harbor]# mkdir -p /data/cert '//创建存储https证书目录'
[root@harbor harbor]# cd /data/cert/
[root@harbor cert]# openssl genrsa -des3 -out server.key 2048 '//创建服务器证书密钥文件 server.key'
Generating RSA private key, 2048 bit long modulus
..............................+++
.................................................................+++
e is 65537 (0x10001)
Enter pass phrase for server.key: '//输入私钥密码。如123123'
Verifying - Enter pass phrase for server.key: '//重复输入私钥密码'
[root@harbor cert]# openssl req -new -key server.key -out server.csr '//创建服务器证书的申请文件 server.csr'
Enter pass phrase for server.key: '/输入前面创建的密码/'
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN '/国家代号,中国输入CN/'
State or Province Name (full name) []:JS '//省名称'
Locality Name (eg, city) [Default City]:NJ '//市名称'
Organization Name (eg, company) [Default Company Ltd]:atguigu '//公司英文名'
Organizational Unit Name (eg, section) []:atguigu '//组织名称'
Common Name (eg, your name or your server's hostname) []:hub.atguigu.com ''//常用名称/服务器主机名'
Email Address []:[email protected] '//邮箱地址'
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: '//可不填'
An optional company name []: '//可不填'
[root@harbor cert]# cp server.key server.key.org '//备份一份服务器密钥文件'
[root@harbor cert]# openssl rsa -in server.key.org -out server.key '//去除文件口令'
Enter pass phrase for server.key.org:
writing RSA key
[root@harbor cert]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt '//生成证书文件server.crt'
Signature ok
subject=/C=CN/ST=NJ/L=NJ/O=atguigu/OU=atguigu/CN=hub.atguigu.com/[email protected]
Getting Private key
[root@harbor cert]# chmod a+x * '//给所有文件权限'
运行脚本安装
[root@harbor cert]# cd -
/usr/local/harbor
[root@harbor harbor]# ./install.sh
修改k8s集群节点,harbor和宿主机本地域名解析文件
[root@k8s-master ~]# echo "192.168.233.134 hub.atguigu.com" >> /etc/hosts '//三个节点添加本地解析'
[root@k8s-master ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.233.128 k8s-master
192.168.233.129 k8s-node01
192.168.233.130 k8s-node02
192.168.233.134 hub.atguigu.com
[root@harbor harbor]# vim /etc/hosts '//harbor节点也要添加'
添加
192.168.233.128 k8s-master
192.168.233.129 k8s-node01
192.168.233.130 k8s-node02
192.168.233.134 hub.atguigu.com
[root@harbor harbor]# docker ps -a '//查看容器状态是否都是up'
修改Windows本地域名解析文件,使用管理员身份登陆系统打开并保存
宿主机访问harbor网页
尝试使用docker登陆harbor
[root@k8s-node01 ~]# docker login https://hub.atguigu.com
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
上传镜像
[root@harbor harbor]# docker images '//查看docker镜像'
[root@harbor harbor]# docker pull photon '//拉取镜像'
[root@harbor harbor]# docker tag photon:latest hub.atguigu.com/library/photon:latest '//更改镜像名称'
[root@harbor harbor]# docker push hub.atguigu.com/library/photon:latest '//上传镜像到harbor仓库'
刷新harbor仓库,发现上传成功
在k8s集群中创建pod,查看镜像下载情况
[root@k8s-master ~]# kubectl run nginx-deployment --image=hub.atguigu.com/library/photon:latest --port=80 --replicas=1
测试完成,harbor私有仓库搭建成功