OpenShift Origin v3.9 的环境建立和应用部署(前篇)
後半請至此處。
首先
因为我已经在OpenShift Origin v3.9中建立了环境,并成功从GitHub部署了我的自定义应用程序,所以我将写下此过程的步骤。
在进行搭建之前,我进行了各种搜索,但找到的示例要么是最小配置(一个Master节点和两个Node节点),要么只是显示Hello World,都不够实用。
因此,我决定写一个更实用和系统化的例子。
虽然内容很长,但大部分是在OpenShift安装之前进行服务器设置,所以并不难。前半部分是关于OpenShift的安装步骤,后半部分是关于应用程序的部署。
1. 构成与前提
-
- KVM 上の仮想マシーンにOpenShift の環境を構築
-
- Master, Infra Node, application Node それぞれ3台ずつ
-
- GlusterFS で内部レジストリー、アプリケーション用データを保全
-
- 物理マシーン、仮想マシーン全てCentOS7
-
- 物理マシーンにVlan Interface, Bridge Interface それぞれvlan205, br205 を作成
-
- 仮想マシーンはks ファイルから作成
-
- 仮想マシーン構築にはCentOS-7-x86_64-DVD-1804.iso を使用
-
- 仮想マシーンのdefault-zone はinternal を指定
-
- 構築作業は全てroot で行うものとする
[マシーン名] と書いてあったらそのマシーンで作業するという意味

2. 准备
2-1. 域名系統註冊
注册域名并进行 DNS 登记。
假设我们在这里注册了一个名为 example.com 的域名,并使用通配符 *.example.com 进行了 DNS 登记。实际搭建时,请将所有的 example.com 部分替换为您自己环境中的内容。
2-2. 防火墙端口转发设置
设定将来自外部的TCP端口80、443、8443的访问直接转发至lb-01的相同端口。
2-3. 建构物理机械
在最小配置下安装CentOS7并安装KVM。
yum -y update
yum -y groupinstall "Virtualization Host"
yum -y install virt-install virt-top virt-clone
systemctl start libvirtd
systemctl enable libvirtd
创建 vlan 和 bridge。将 bond0 更改为适合自己环境的名称。
nmcli c add type bridge ifname br205 con-name br205
nmcli c mod br205 bridge.stp no
nmcli c mod br205 ipv4.method disabled ipv6.method ignore
nmcli c add type vlan ifname vlan205 con-name vlan205 dev bond0 id 205
nmcli c mod vlan205 connection.master br205 connection.slave-type bridge
请下载CentOS-7-x86_64-DVD-1804.iso并保存至/opt/Linux目录中。
搭建内部DNS服务器。
[物理机器]
创建一个 ks 文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.6 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=8.8.8.8 --noipv6
network --hostname=dns-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=1024 --grow --ondisk=vda
volgroup centos pv.1
logvol swap --fstype swap --name=swap --vgname=centos --size=1024
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘映像。
qemu-img create -f qcow2 /var/lib/libvirt/images/dns-01.qcow2 8G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=dns-01 \
--vcpus=1 \
--ram=1024 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/dns-01.qcow2,size=8,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./dns-01.ks \
--extra-args='ks=file:/dns-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
[dns-01]
安装 firewalld 并配置 dnsmasq。
yum -y update
nmcli c mod eth0 connection.zone internal
firewall-cmd --set-default-zone=internal
firewall-cmd --zone=internal --add-service=dns --permanent
firewall-cmd --zone=internal --remove-service=mdns --permanent
firewall-cmd --zone=internal --remove-service=samba-client --permanent
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent
yum -y install dnsmasq
reboot
在主机文件中添加内容。
192.168.205.1 lb-01 lb-01.example.com console console.example.com
192.168.205.3 ansible ansible.example.com
192.168.205.6 dns-01 dns-01.example.com
192.168.205.8 repo-01 repo-01.example.com
192.168.205.9 ntp-01 ntp-01.example.com
192.168.205.11 master-01 master-01.example.com
192.168.205.12 master-02 master-02.example.com
192.168.205.13 master-03 master-03.example.com
192.168.205.14 infra-01 infra-01.example.com
192.168.205.15 infra-02 infra-02.example.com
192.168.205.16 infra-03 infra-03.example.com
192.168.205.17 node-01 node-01.example.com
192.168.205.18 node-02 node-02.example.com
192.168.205.19 node-03 node-03.example.com
192.168.205.21 gfs-01 gfs-01.example.com
192.168.205.22 gfs-02 gfs-02.example.com
192.168.205.23 gfs-03 gfs-03.example.com
192.168.205.24 gfs-04 gfs-04.example.com
192.168.205.25 gfs-05 gfs-05.example.com
192.168.205.26 gfs-06 gfs-06.example.com
编辑并启动dnsmasq的配置文件。
port=53
domain-needed
bogus-priv
resolv-file=/etc/dnsmasq.resolv.conf
strict-order
local=/example.com/
expand-hosts
domain=example.com
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
nameserver 8.8.8.8
systemctl start dnsmasq
systemctl enable dnsmasq
编辑hosts文件后,需要重新启动dnsmasq。
创建本地代码库。
虽然没有问题,但原始相关的软件包下载可能需要超过一个小时的时间。因为一开始可能要反复创建和破坏环境,所以建议提前创建仅包含原始相关软件包的本地仓库,以节省时间。
创建一个物理机文件的KS文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.8 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=repo-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=1024 --grow --ondisk=vda
volgroup centos pv.1
logvol swap --fstype swap --name=swap --vgname=centos --size=1024
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘映像。
qemu-img create -f qcow2 /var/lib/libvirt/images/repo-01.qcow2 8G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=repo-01 \
--vcpus=1 \
--ram=1024 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/repo-01.qcow2,size=8,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./repo-01.ks \
--extra-args='ks=file:/repo-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
[repo-01]
进行firewalld的设置,并安装所需的本地仓库包。
yum -y update
nmcli c mod eth0 connection.zone internal
firewall-cmd --set-default-zone=internal
firewall-cmd --zone=internal --add-service=http --permanent
firewall-cmd --zone=internal --remove-service=mdns --permanent
firewall-cmd --zone=internal --remove-service=samba-client --permanent
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent
yum install -y httpd yum-utils createrepo centos-release-openshift-origin39
systemctl enable httpd
reboot
为了与特定原件相关的包进行下载并创建软件仓库。
mkdir /var/www/html/repo
createrepo --database /var/www/html/repo
yum install -y --downloadonly --downloaddir=/var/www/html/repo origin origin-clients origin-master origin-node origin-sdn-ovs
createrepo --update /var/www/html/repo
2-6. NTP服务器
即使没有这个也可以工作,但如果要创建,应该使用一种普遍的方法进行创建。
创建方法交给其他文章。
后续步骤是基于已创建的情况下的。
3. 创建 OpenShift 运行虚拟机
3-1. lb-01
3-1. 磅 -01
[物理机器]
创建一个ks文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.1 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=lb-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=1024 --grow --ondisk=vda
volgroup centos pv.1
logvol swap --fstype swap --name=swap --vgname=centos --size=1024
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘映像。
qemu-img create -f qcow2 /var/lib/libvirt/images/lb-01.qcow2 8G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=lb-01 \
--vcpus=2 \
--ram=2048 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/lb-01.qcow2,size=8,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./lb-01.ks \
--extra-args='ks=file:/lb-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
3-2 主-01
[物理机器]
创建ks文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.11 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=master-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=65536 --ondisk=vda
volgroup centos pv.1
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘镜像。
qemu-img create -f qcow2 /var/lib/libvirt/images/master-01.qcow2 128G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=master-01 \
--vcpus=8 \
--ram=24576 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/master-01.qcow2,size=128,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./master-01.ks \
--extra-args='ks=file:/master-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
使用不同的主机名和IP地址创建虚拟机master-02和master-03。
3-3. 基础设施-01
创建物理机器
创建KS文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.14 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=infra-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=32768 --ondisk=vda
volgroup centos pv.1
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘映像。
qemu-img create -f qcow2 /var/lib/libvirt/images/infra-01.qcow2 96G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=infra-01 \
--vcpus=8 \
--ram=16384 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/infra-01.qcow2,size=96,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./infra-01.ks \
--extra-args='ks=file:/infra-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
更改主机名和IP地址,创建infra-02,03,node-01,02,03的虚拟机。
3-4. 不同人的身份证
创建一个物理机器的ks文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.21 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=gfs-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=8192 --ondisk=vda
volgroup centos pv.1
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘映像。
qemu-img create -f qcow2 /var/lib/libvirt/images/gfs-01.qcow2 200G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=gfs-01 \
--vcpus=2 \
--ram=8192 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/gfs-01.qcow2,size=200,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./gfs-01.ks \
--extra-args='ks=file:/gfs-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
更改主机名和IP地址以创建gfs-02,03,04,05,06的虚拟机。
创建和设置作业服务器
4-1.创建ansible-01
创建一个物理机制文件。
cmdline
install
lang ja_JP.UTF-8
keyboard jp106
network --device eth0 --onboot yes --bootproto=static --ip=192.168.205.3 --netmask=255.255.255.224 --gateway=192.168.205.30 --nameserver=192.168.205.6 --noipv6
network --hostname=ansible-01
zerombr
bootloader --location=mbr --append="crashkernel=auto biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
clearpart --linux --drives=vda
part /boot --fstype xfs --size=1024 --ondisk=vda
part pv.1 --size=1024 --grow --ondisk=vda
volgroup centos pv.1
logvol swap --fstype swap --name=swap --vgname=centos --size=1024
logvol / --fstype xfs --name=root --vgname=centos --size=1024 --grow
rootpw --plaintext rootpassword
user --groups=wheel --name=user-01 --password=user-01password --plaintext
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
firstboot --disabled
timezone --utc Asia/Tokyo
reboot
%packages --nobase
%end
创建磁盘镜像。
qemu-img create -f qcow2 /var/lib/libvirt/images/ansible-01.qcow2 8G
创建虚拟机。
virt-install --connect=qemu:///system \
--name=ansible-01 \
--vcpus=1 \
--ram=1024 \
--accelerate \
--hvm \
--disk /var/lib/libvirt/images/ansible-01.qcow2,size=8,format=qcow2,bus=virtio \
--location='/opt/Linux/CentOS-7-x86_64-DVD-1804.iso' \
--network bridge=br205,model=virtio \
--nographics \
--initrd-inject=./ansible-01.ks \
--extra-args='ks=file:/ansible-01.ks biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8' \
--os-type=linux \
--os-variant=centos7.0 \
--arch=x86_64
[ansible-01]
安装 firewalld 并进行配置设置,安装所需的软件包。
yum -y update
nmcli c mod eth0 connection.zone internal
firewall-cmd --set-default-zone=internal
firewall-cmd --zone=internal --remove-service=mdns --permanent
firewall-cmd --zone=internal --remove-service=samba-client --permanent
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent
yum install -y git epel-release python2-passlib httpd-tools java-1.8.0-openjdk-headless patch
yum install -y --enablerepo=epel ansible pyOpenSSL
reboot
4-2. 配置 OpenShift 操作虚拟机的设置。
[ansible-01]
创建没有密码的密钥。
ssh-keygen
发送密钥给各个服务器。
ssh-copy-id -i ~/.ssh/id_rsa.pub lb-01
ssh-copy-id -i ~/.ssh/id_rsa.pub master-01
ssh-copy-id -i ~/.ssh/id_rsa.pub master-02
ssh-copy-id -i ~/.ssh/id_rsa.pub master-03
ssh-copy-id -i ~/.ssh/id_rsa.pub infra-01
ssh-copy-id -i ~/.ssh/id_rsa.pub infra-02
ssh-copy-id -i ~/.ssh/id_rsa.pub infra-03
ssh-copy-id -i ~/.ssh/id_rsa.pub node-01
ssh-copy-id -i ~/.ssh/id_rsa.pub node-02
ssh-copy-id -i ~/.ssh/id_rsa.pub node-03
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-01
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-02
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-03
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-04
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-05
ssh-copy-id -i ~/.ssh/id_rsa.pub gfs-06
4-2-1. lb-01的设置
[ansible-01]
进行yum更新
for host in lb-01;
do ssh ${host} 'yum -y update'
done
防火墙、时间同步器、ifcfg-eth0 的设置。
for host in lb-01 ;
do ssh ${host} 'nmcli c mod eth0 connection.zone internal; \
firewall-cmd --set-default-zone=internal; \
firewall-cmd --zone=internal --add-service=http --permanent; \
firewall-cmd --zone=internal --add-service=https --permanent; \
firewall-cmd --zone=internal --remove-service=mdns --permanent; \
firewall-cmd --zone=internal --remove-service=samba-client --permanent; \
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent; \
sed -i -e "/server/s/^/#/" /etc/chrony.conf; \
sed -i -e "s/server 3\.centos\.pool\.ntp\.org iburst/server 3.centos.pool.ntp.org iburst\nserver 192.168.205.9 iburst\nport 0/" /etc/chrony.conf; \
sed -i -e "/HWADDR/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "/UUID/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "\$aDOMAIN=example.com" /etc/sysconfig/network-scripts/ifcfg-eth0;'
done
重新启动。
for host in lb-01;
do ssh ${host} 'reboot'
done
4-2-2. 师傅、基础设施、节点的设置
请进行yum更新。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'yum -y update'
done
火牆、時鐘伺服器、以及ifcfg-eth0的配置設定。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'nmcli c mod eth0 connection.zone internal; \
firewall-cmd --set-default-zone=internal; \
firewall-cmd --zone=internal --remove-service=mdns --permanent; \
firewall-cmd --zone=internal --remove-service=samba-client --permanent; \
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent; \
sed -i -e "/server/s/^/#/" /etc/chrony.conf; \
sed -i -e "s/server 3\.centos\.pool\.ntp\.org iburst/server 3.centos.pool.ntp.org iburst\nserver 192.168.205.9 iburst\nport 0/" /etc/chrony.conf; \
sed -i -e "/HWADDR/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "/UUID/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "\$aDOMAIN=example.com" /etc/sysconfig/network-scripts/ifcfg-eth0;'
done
安装必要的软件包。
Note: The translation assumes that the phrase “必要パッケージのインストール” is written in Japanese and not in Chinese.
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'yum -y install wget git net-tools bind-utils yum-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct'
done
创建 VDA3。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'echo -e "n\np\n3\n\n\nt\n3\n8e\nw\n" | fdisk /dev/vda'
done
重新启动。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'reboot'
done
安装Docker。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'vgcreate docker-vg /dev/vda3; \
yum -y install docker-1.13.1; \
rpm -V docker-1.13.1; \
echo "VG=docker-vg" > /etc/sysconfig/docker-storage-setup; \
docker-storage-setup; \
systemctl start docker; \
systemctl enable docker;'
done
仅添加主要的附加包。
for host in master-01 \
master-02 \
master-03;
do ssh ${host} "yum -y install centos-release-gluster httpd-tools"
done
如果搭建了本地代码库,请执行以下操作。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} 'yum -y install yum-plugin-priorities; \
echo -e "[local]\nname=Local Repo\nbaseurl=http://192.168.205.8/repo\ngpgcheck=0\npriority=1" > /etc/yum.repos.d/local.repo; \
yum clean all;'
done
4-2-3. 建立 gfs 的配置
[ansible-01]
执行yum update命令进行更新。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'yum -y update'
done
防火牆d、chrony、ifcfg-eth0、SELinux的設定。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'nmcli c mod eth0 connection.zone internal; \
firewall-cmd --set-default-zone=internal; \
firewall-cmd --permanent --zone=internal --add-rich-rule="rule family="ipv4" source address="192.168.205.0/27" accept"; \
firewall-cmd --zone=internal --remove-service=mdns --permanent; \
firewall-cmd --zone=internal --remove-service=samba-client --permanent; \
firewall-cmd --zone=internal --remove-service=dhcpv6-client --permanent; \
sed -i -e "/server/s/^/#/" /etc/chrony.conf; \
sed -i -e "s/server 3\.centos\.pool\.ntp\.org iburst/server 3.centos.pool.ntp.org iburst\nserver 192.168.205.9 iburst\nport 0/" /etc/chrony.conf; \
sed -i -e "/HWADDR/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "/UUID/s/^/#/" /etc/sysconfig/network-scripts/ifcfg-eth0; \
sed -i -e "\$aDOMAIN=example.com" /etc/sysconfig/network-scripts/ifcfg-eth0; \
setsebool -P virt_sandbox_use_fusefs on; \
setsebool -P virt_use_fusefs on;'
done
安装 GlusterFS。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'yum -y install centos-release-gluster; \
yum -y install glusterfs-server gluster-block; \
systemctl enable glusterd; \
systemctl enable gluster-blockd;'
done
编辑logrotate配置。
由于GlusterFS的日志一次性达到了数GB,并且分区使用率达到了100%,所以我们决定将日志文件按日分割。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'sed -i -e "s/weekly/daily/" /etc/logrotate.d/glusterfs;'
done
创建VDA3。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'echo -e "n\np\n3\n\n\nt\n3\n8e\nw\n" | fdisk /dev/vda'
done
重启。
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'reboot'
done
4-2-4. 启动确认和备份
[ansible-01]
请确认是否显示为全部活动。
for host in master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03;
do ssh ${host} "systemctl is-active docker;"
done
for host in gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} "systemctl is-active glusterd; systemctl is-active gluster-blockd;"
done
如果你已经完成了这一步,强烈建议你关闭OpenShift虚拟机并备份磁盘镜像文件。如果要卸载OpenShift并重新安装,卸载可能会失败并留下垃圾或删除一些必要的内容,因此最可靠的方法是用新的虚拟机磁盘镜像文件替换原有的。
如果要一键关闭,请执行以下操作。
for host in lb-01 \
master-01 \
master-02 \
master-03 \
infra-01 \
infra-02 \
infra-03 \
node-01 \
node-02 \
node-03 \
gfs-01 \
gfs-02 \
gfs-03 \
gfs-04 \
gfs-05 \
gfs-06;
do ssh ${host} 'shutdown -h now'
done
5. 安装 OpenShift
5-1. 安装
[自动化-01]
下载 OpenShift 的 Ansible yaml 文件。
git clone https://github.com/openshift/openshift-ansible
cd openshift-ansible
git checkout release-3.9
编辑yaml文件。
根据2018/10/12的确认,似乎已经进行了修正。
因此,在这里不需要进行修正,但为了以防万一,我会在文章中留下记录。
resturl: "http://{% if glusterfs_heketi_is_native %}{{ glusterfs_heketi_route }}{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %}"
↓
resturl: "http://{% if glusterfs_heketi_is_native %}heketi-{{ glusterfs_name }}.{{ glusterfs_namespace }}.svc.cluster.local:8080{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %}"
resturl: "http://{% if glusterfs_heketi_is_native %}{{ glusterfs_heketi_route }}{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %}"
↓
resturl: "http://{% if glusterfs_heketi_is_native %}heketi-{{ glusterfs_name }}.{{ glusterfs_namespace }}.svc.cluster.local:8080{% else %}{{ glusterfs_heketi_url }}:{{ glusterfs_heketi_port }}{% endif %}"
创建库存文件。
通过openshift_hosted_registry_storage_volume_size的值来更改内部注册表的大小。
[masters]
master-0[1:3].example.com
[etcd]
master-0[1:3].example.com
[nodes]
master-0[1:3].example.com
infra-0[1:3].example.com openshift_node_labels="{'region': 'infra', 'zone': 'default', 'node-role.kubernetes.io/infra': 'true'}"
node-0[1:3].example.com openshift_node_labels="{'region': 'primary', 'zone': 'default'}"
[lb]
console.example.com
[glusterfs]
gfs-04.example.com glusterfs_ip=192.168.205.24 glusterfs_devices='[ "/dev/vda3" ]'
gfs-05.example.com glusterfs_ip=192.168.205.25 glusterfs_devices='[ "/dev/vda3" ]'
gfs-06.example.com glusterfs_ip=192.168.205.26 glusterfs_devices='[ "/dev/vda3" ]'
[glusterfs_registry]
gfs-01.example.com glusterfs_ip=192.168.205.21 glusterfs_devices='[ "/dev/vda3" ]'
gfs-02.example.com glusterfs_ip=192.168.205.22 glusterfs_devices='[ "/dev/vda3" ]'
gfs-03.example.com glusterfs_ip=192.168.205.23 glusterfs_devices='[ "/dev/vda3" ]'
[OSEv3:children]
masters
nodes
etcd
lb
glusterfs
glusterfs_registry
[OSEv3:vars]
ansible_user=root
ansible_become=yes
os_firewall_use_firewalld=true
openshift_deployment_type=origin
openshift_release=v3.9
openshift_master_default_subdomain=app.example.com
openshift_master_cluster_method=native
openshift_master_cluster_hostname=console.example.com
openshift_master_cluster_public_hostname=console.example.com
openshift_master_logging_public_url=https://kibana.example.com
openshift_disable_check=memory_availability,disk_availability,package_version,docker_image_availability
openshift_docker_options="--insecure-registry=172.30.0.0/16 --selinux-enabled --log-opt max-size=1M --log-opt max-file=3"
openshift_router_selector="region=infra"
openshift_enable_service_catalog=true
ansible_service_broker_install=false
debug_level=2
openshift_master_dynamic_provisioning_enabled=true
# registry
openshift_hosted_registry_replicas=3
openshift_hosted_registry_selector="region=infra"
openshift_hosted_registry_storage_kind=glusterfs
openshift_hosted_registry_storage_volume_size=64Gi
# CNS storage for applications
openshift_storage_glusterfs_is_native=false
openshift_storage_glusterfs_namespace=app-glusterfs
openshift_storage_glusterfs_name=storage
openshift_storage_glusterfs_storageclass=true
openshift_storage_glusterfs_block_deploy=false
openshift_storage_glusterfs_heketi_is_native=true
openshift_storage_glusterfs_heketi_executor=ssh
openshift_storage_glusterfs_heketi_ssh_port=22
openshift_storage_glusterfs_heketi_ssh_user=root
openshift_storage_glusterfs_heketi_ssh_sudo=false
openshift_storage_glusterfs_heketi_ssh_keyfile="/root/.ssh/id_rsa"
# CNS storage for OpenShift infrastructure
openshift_storage_glusterfs_is_native=false
openshift_storage_glusterfs_registry_namespace=infra-glusterfs
openshift_storage_glusterfs_registry_name=registry
openshift_storage_glusterfs_registry_block_deploy=true
openshift_storage_glusterfs_registry_block_storageclass=true
openshift_storage_glusterfs_registry_block_storageclass_default=true
openshift_storage_glusterfs_registry_heketi_is_native=true
openshift_storage_glusterfs_registry_heketi_executor=ssh
openshift_storage_glusterfs_registry_heketi_ssh_port=22
openshift_storage_glusterfs_registry_heketi_ssh_user=root
openshift_storage_glusterfs_registry_heketi_ssh_sudo=false
openshift_storage_glusterfs_registry_heketi_ssh_keyfile="/root/.ssh/id_rsa"
提前确认。
建议在保存标准输出作为日志的同时进行操作。
如果出现错误,请查看日志并修正相应部分。
重复此过程直到没有出现错误为止。
ansible-playbook -i inventory/hosts playbooks/prerequisites.yml -vvv
安装。
建议在执行过程中将标准输出保存为日志。
ansible-playbook -i inventory/hosts playbooks/deploy_cluster.yml -vvv
如果遇到错误,请将其回滚至备份的OpenShift操作虚拟机并进行修正,然后从prerequisites.yml重新执行。
如果不进行回滚,重新执行deploy_cluster.yml也无法成功。
5-2. 用户创建
[主控-01]
创建账号。
htpasswd -b -c /etc/origin/master/htpasswd <user> <password>
给创建的用户分配管理员权限。
oadm policy add-cluster-role-to-user cluster-admin <user>
5-3. HA Proxy 的配置
在HA Proxy上新增配置。
新增配置将端口80和443的访问转发至infra-01,02和03。
frontend router-http
bind *:80
default_backend router-http
mode tcp
option tcplog
backend router-http
balance source
mode tcp
server router1 192.168.205.14:80 check
server router2 192.168.205.15:80 check
server router3 192.168.205.16:80 check
frontend router-https
bind *:443
default_backend router-https
mode tcp
option tcplog
backend router-https
balance source
mode tcp
server router1 192.168.205.14:443 check
server router2 192.168.205.15:443 check
server router3 192.168.205.16:443 check
重新启动 HA Proxy
systemctl restart haproxy
5-4. 确认
请尝试使用在https://console.example.com:8443上创建的帐户登录并确认是否成功。
5-5. 安装指标和日志记录
在 inventory 文件中添加了有关度量和日志安装定义的内容。
# metrics
openshift_metrics_install_metrics=true
openshift_metrics_hawkular_nodeselector={"region":"infra"}
openshift_metrics_cassandra_nodeselector={"region":"infra"}
openshift_metrics_heapster_nodeselector={"region":"infra"}
openshift_metrics_cassandra_pvc_size=8Gi
openshift_metrics_storage_kind=dynamic
openshift_metrics_cassanda_pvc_storage_class_name=glusterfs-registry-block
openshift_metrics_hawkular_hostname=hawkular-metrics.example.com
openshift_metrics_image_version=latest
# logging
openshift_logging_install_logging=true
openshift_logging_es_cluster_size=3
openshift_logging_es_nodeselector={"region":"infra"}
openshift_logging_kibana_nodeselector={"region":"infra"}
openshift_logging_curator_nodeselector={"region":"infra"}
openshift_logging_storage_kind=dynamic
openshift_logging_es_pvc_size=8Gi
openshift_logging_es_pvc_dynamic=true
openshift_logging_es_pvc_storage_class_name=glusterfs-registry-block
openshift_logging_image_version=latest
执行metrics和logging的安装用Playbook。
ansible-playbook -i inventory/hosts playbooks/openshift-metrics/config.yml -vvv
ansible-playbook -i inventory/hosts playbooks/openshift-logging/config.yml -vvv
指标和日志分别部署在名为openshift-infra和logging的项目中的专用容器中。
然而,在最后确认本文内容之前,为了验证,我尝试进行了所有的安装工作,但是两者的容器部署都失败了。之前指标的部署成功了一段时间。
这两个对于自己的应用程序的部署和运行没有任何影响。
如果要卸载,请执行以下操作。
ansible-playbook -i inventory/hosts playbooks/openshift-metrics/config.yml -e openshift_metrics_install_metrics=false
ansible-playbook -i inventory/hosts playbooks/openshift-logging/config.yml -e openshift_logging_install_logging=false
总结
能够在位于KVM上的CentOS7虚拟机的老旧基础设施上成功安装OpenShift。
尽管我们不确定metrics和logging的正确安装方法,但即使没有它们也可以运行,因此我们将继续部署自己的应用程序。
如果有人知道metrics和logging的正确安装方法,请告诉我。
這裡是後編。
请提供以下资料的参考
先决条件
主机准备
高级安装
使用GlusterFS进行持久存储
容器原生存储 3.9
使用heketi的服务名作为URL
OpenShift Origin 3.9的指标失败,原因是图像标签不正确。