该操作在CRT中进行,由于自己使用的虚拟机,所有关于上传镜像部分会和实际操作不一样,但是本质上是一样的。
本实验环境采用server+client两个节点部署
此次操作所需的IP可自己自行设置。
所需镜像:
XianDian-PaaS-v2.2
CentOS-7-x86_64-DVD-1511(在服务器上搭建docker服务是不需要上传这个镜像的)
下面的基础环境1-4步骤在两个节点均要设置,不能遗漏。
# vi /etc/sysconfig/selinux
SELINUX=disabled
#reboot
# getenforce
Disabled
# systemctl stop firewalld.service
# iptables –F
# iptables –X
# iptables –Z
# /usr/sbin/iptables-save
#vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0
保存退出
# sysctl –p
#hostnamectl set-hostname server
#bash
# vi /etc/hosts(内网IP)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.3.137 server
10.0.3.138 client
# ping client
PING client (10.0.3.138) 56(84) bytes of data.
64 bytes from client (10.0.3.138): icmp_seq=1 ttl=64 time=1.02 ms
64 bytes from client (10.0.3.138): icmp_seq=2 ttl=64 time=0.400 ms
# hostnamectl set-hostname client
# bash
# vi /etc/hosts(内网IP)
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.3.137 server
10.0.3.138 client
# ping server
PING server (10.0.3.137) 56(84) bytes of data.
64 bytes from server (10.0.3.137): icmp_seq=1 ttl=64 time=0.531 ms
64 bytes from server (10.0.3.137): icmp_seq=2 ttl=64 time=0.327 ms
# mv /etc/yum.repos.d/* /media/
第一个是没有在虚拟机连接镜像,第二个连接上了镜像,一定要连上镜像在做。
将我们的XianDian-PaaS-v2.2.iso通过CRT上传到系统中,然后挂载到/mnt,拷贝出mnt里面所有的文件夹到/opt上。lsblk的用处我在搭建iaas平台的时候,展示过,在这里就不介绍了。
#lsblk
#mount -o loop /dev/sr0 /mnt/
#mkdir /opt/centos
#cp -rvf /mnt/* /opt/centos/
#umount /mnt/
#mount -o loop /dev/sr1 /mnt/
#cp -rvf /mnt/* /opt/
#umount /mnt/
此处我是在虚拟机的基础上连接着CRT上操作,所以多挂载了一个镜像(centos镜像),如果不多挂镜像,那么在安装docker服务时,就会一直报错。同样在创建repo文件时,我也多编辑centos文件吧,我也表达不清楚。
# vi /etc/yum.repos.d/docker.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[docker]
name=docker
baseurl=file:///opt/docker
gpgcheck=0
enabled=1
# yum install -y vsftpd
# vi /etc/vsftpd/vsftpd.conf
添加anon_root=/opt/
退出保存
# systemctl restart vsftpd
# systemctl enable vsftpd
# vi /etc/yum.repos.d/docker.repo (外网)
[centos]
name=centos
baseurl=ftp://192.168.100.16/centos
gpgcheck=0
enabled=1
[docker]
name=docker
baseurl=ftp://192.168.100.16/docker
gpgcheck=0
enabled=1
#systemctl stop firewalld
#systemctl disable firewalld
#yum clean all
#yum list
# yum install -y docker
# systemctl restart docker
# systemctl enable docker
以下部署仓库或者启动服务什么的都要在server节点上进行
#cd /opt/images/rancher1.6.5/
# ll
-rw-r--r-- 1 root root 33918976 Oct 17 10:20 registry_latest.tar
# docker load -i registry_latest.tar
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/registry latest c9bd19d022f6 15 months ago 33.27 MB
# docker run -d -p 5000:5000 --restart=always --name registry docker.io/registry:latest
20a07207bf28256d13fbc53cf2a1d978a4827bf8f360b32a8106d996f024c001
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
20a07207bf28 docker.io/registry:latest "/entrypoint.sh /etc/" 8 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp registry
注意:两个节点都要添加仓库地址。
# vi /etc/sysconfig/docker //添加下面两行
ADD_REGISTRY='--add-registry 10.0.3.137:5000'
INSECURE_REGISTRY='--insecure-registry 10.0.3.137:5000'
# systemctl daemon-reload
# systemctl restart docker
# docker info (client节点之后就不在执行,任何步骤)
# docker images
# docker tag c9bd19d022f6 10.0.3.137:5000/registry:latest
# docker push 10.0.3.137:5000/registry:latest
至此仓库就建立好了,我们需要将所有镜像全部推送到仓库中,提供给其他节点使用。
# ll
-rw-r--r-- 1 root root 1000050176 Jan 29 06:23 rancher_server_v1.6.5.tar
# docker load -i rancher_server_v1.6.5.tar
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
f89070da7581 3 weeks ago 984.9 MB
10.0.3.137:5000/registry latest c9bd19d022f6 15 months ago 33.27 MB
docker.io/registry latest c9bd19d022f6 15 months ago 33.27 MB
# docker tag f89070da7581 10.0.3.137:5000/rancher/server:v1.6.5
# docker push 10.0.3.137:5000/rancher/server:v1.6.5
# docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:v1.6.5;
2ff52cf39d6f2637ac300e7d430dc828fba99cef4ec118793e91e9d680a16509
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2ff52cf39d6f rancher/server:v1.6.5 "/usr/bin/entry /usr/" 18 seconds ago Up 6 seconds 3306/tcp, 0.0.0.0:8080->8080/tcp modest_turing
20a07207bf28 docker.io/registry:latest "/entrypoint.sh /etc/" 39 minutes ago Up 38 minutes 0.0.0.0:5000->5000/tcp registry
Rancher-server的访问地址是:serverIP:8080
搭建docker平台完成