A场次题目:Openstack 平台部署与运维 任务1 私有云平台环境初始化 1.初始化操作系统 使用提供的用户名密码,登录竞赛云平台。根据表 1 中的 IP 地址规划,设置各服务器节点的 IP 地址,确保网络正常通信,设置控制节点主机名为 Contro ller,计算节点主机名为 Compute,并修改 hosts 文件将 IP 地址映射为主机名, 关闭防火墙并设置为开机不启动,设置 SELinux 为 Permissive 模式并设置永久 关闭。请查看控制节点和计算节点主机名,使用命令查看 SELinux 状态,使用 head 命令、tail 命令和 cut 命令提取出永久关闭 SELinux 的关键信息。 将以上命令及返回结果提交到答题框
配置host
1 2 3 4 5 6 vi /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.17.31.10 controller 172.17.31.20 compute
关闭防火墙并设置为开机不启动
1 2 systemctl stop firewalld systemctl disable firewalld
关闭selinux并永久关闭
1 2 3 setenforce 0 vi /etc/selinux/config SELINUX=Permissive
使用命令查看selinux状态
2.挂载安装光盘镜像 将提供的 CentOS-7-x86_64-DVD-1804.iso 和 chinaskills_cloud_iaas.iso 光盘镜像上传到 Controller 节点 /root 目录下,然后在 /opt 目录下使用一条 命令创建/centos 目录和/iaas 目录,并将镜像文件 CentOS-7-x86_64-DVD-1804. iso 挂载到 /centos 目录下,将镜像文件 chinaskills_cloud_iaas.iso 挂载到 /iaas 目录下。 请将以上命令及返回结果返回到答题框。【1 分】
1 2 3 4 mkdir /opt/centosmkdir /opt/iaasmount chinaskills_cloud_iaas.iso /opt/iaas mount CentOS-7-x86_64-DVD-1804.iso /opt/centos
3.搭建文件共享服务器在Controller节点上安装 vsftp 服务器设置开机自启动,请将以上命令 及返回结果提交到答题框。【0.5 分】
1 2 3 4 5 6 7 yum install -y vsftpd vi /etc/vsftpd/vsftpd.conf anon_root=/opt/ systemctl start vsftpd systemctl enable vsftpd
4.设置 yum 源
将 ftp 仓库设置为 /opt/,为 controller 节点设置本地 yum 源,yum 源文件名为 local.repo;为 compute 配置 ftp 源,yum 源文件名称为 ftp.repo,其中ftp服务器地址为 controller 节点 IP.请将两个节点的 yum 源文件内容提交到答题框。【0.5 分】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 mv /etc/yum.repos.d/* /etc/yumvi /etc/yum.repos.d/local.repo [centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1 [iaas] name=iaas baseurl=file:///opt/iaas/iaas-repo mv /etc/yum.repos.d/* /etc/yumvi /etc/yum.repos.d/ftp.repo [centos] name=centos baseurl=ftp://172.17.31.10/centos gpgcheck=0 enabled=1 [iaas] name=iaas baseurl=ftp://172.17.31.20/iaas/iaas-repo
5.部署时间同步服务器
在 Controller 节点上部署 chrony 服务器,允许其他节点同步时间,启动服务并设置为开机启动;在 compute 节点上指定 controller 节点为上游 NTP 服务器,重启服务并设为开机启动。
请在控制节点上使用 chronyc 命令同步控制节点的系统时间。【1 分】
#在centroller节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server controller iburst # Record the rate at which the system clock gains/losses time. driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second. makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. #hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. #minsources 2 # Allow NTP client access from local network. #allow 192.168.0.0/16 # Serve time even if not synchronized to a time source. #local stratum 10 # Specify file containing keys for NTP authentication. #keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. #log measurements statistics tracking allow 172.17.31.0/24 local stratum 10 systemctl restart chronyd systemctl enable chronyd
在compute节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 vi /etc/chrony.conf server controller iburst driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync logdir /var/log/chrony systemctl restart chronyd systemctl enable chronyd
任务二 Openstack 搭建任务 1.修改变量文件 在控制节点和计算节点上分别安装 iaas-xiandian 软件包,修改配置脚本文件中基本变量(配置脚本文件为/etc/xiandian/openrc.sh)。修改完成后使用命令生效该变量文件,然后执行 echo $INTERFACE_IP 命令。
请将命令和返回结果提交到答题框。【0.5 分】
在controller节点
1 2 3 4 5 6 7 8 9 yum install -y iaas-xiandian vi /etc/xiandian/openrc.sh # tips: :%s/#// 去除# :%s/PASS=/PASS=000000 source /etc/xiandian/openrc.sh echo $INTERFACE_IP
在comopute节点
1 2 3 4 5 6 7 8 yum install -y iaas-xiandian # 登录到controller scp /etc/xiandian/openrc.sh root@172.17.31.20:/etc/xiandian/openrc.sh 修改INTERFACE_IP即可 source /etc/xiandian/openrc.sh echo $INTERFACE_IP
2.搭建数据库组件 使用提供的脚本框架 iaas-install-mysql.sh 填充脚本,在 controller 节点上安装 mariadb、mencached、rabbitmq 等服务并完成相关配置。完成后修改配置文件将 mencached 最大连接数修改为 2048。
请将修改后的配置文件提交到答题框。【1 分】
在controller节点
1 2 3 4 5 iaas-install-mysql.sh vi /etc/sysconfig/memcached MAXCONN="2048"
3.搭建认证服务组件 使用提供的脚本框架 iaas-install-keystone.sh 填充脚本,在 controlle r 节点上安装 keystone 服务并完成相关配置。完成后使用 openstack 命令请求 一个 token。
请将以上命令和返回结果提交到答题框。【1 分】
在controller节点
1 2 iaas-install-keystone.sh openstack token issue
4.搭建镜像服务组件 使用提供的脚本框架 iaas-install-glance.sh 填充脚本,在 controller 节点上安装 glance 服务并完成相关配置。完成后请将 cirros-0.3.4-x86_64-disk.img 上传到控制节点的 /root 目录下,然后使用 openstack 命令将该镜像上传到 openstack 平台镜像命名为 cirros。
请将镜像上传的操作命令和返回结果提交到答题框。【1 分】
在controller节点
1 2 iaas-install-glance.sh openstack image create --disk-format qcow2 --container-format bare --shared cirros </root/cirros-0.3.4-x86_64-disk.img
5.搭建计算服务组件 使用提供的脚本框架 iaas-install-nova-controller.sh 和 iaas-install-nova-compute.sh 填充脚本,在 controller 和 compute 节点上安装 nova 服务并完成配置。完成后请将控制节点的计算资源也加入集群。然后使用 openstack 命令列出能提供计算资源的节点。
将列出计算资源的命令和返回结果提交到答题框。【1.5 分】
在controller节点
1 iaas-install-nova-controller.sh
在compute节点
1 iaas-install-nova-compute.sh
controller:
1 2 3 4 5 6 7 8 把compute节点的名称和IP都改成controller节点的名称和IP vi /etc/iaas-openstack/openrc.sh HOST_IP_NODE=172.17.31.10 HOST_NAME_NODE=controller iaas-install-nova-compute.sh
修改nova配置
1 2 3 cat /etc/nova/nova.conf [libvirt] virt_type=qemu ##在[libvirt]下添加此行即可
6.搭建网络组件并初始化网络 使用提供 的脚本框架 iaas-install-neutron-controller.sh 和 iaas-install-neutron-compute.sh,填充脚本,在 controller 和 compute 节点上安装 neutron 服务并完成配置。创建云主机外部网络 ext-net,子网为 ext-subnet,云主机浮动 IP 可用网段为 172.18.x.100172.18.x.200,网关为 172.18.x.1。创建云主机内部网络 int-net1,子网为 int-subnet1,云主机子网 IP 可用网段为 10.0.0.10010.0.0.200,网关为 10.0.0.1;创建云主机内部网络 int-net2,子网为 int-subnet2,云主机子网 IP 可用网段为 10.0.1.100 ~ 10.0.1.200,网关为 10.0.1.1。添加名为 ext-router 的路由器,添加网关在 ext-net 网络,添加内部端口到 int-net1 网络,完成内部网络 int-net1 和外部网络的连通。
请使用 openstack 命令完成以下任务,完成后将命令和返回结果提交到答题框。【4 分】
controller
1 iaas-install-neutron-controller.sh
compute
1 iaas-insta ll-neutron-compute.sh
创建网络(controller)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # 创建外部网络 openstack network create --external --provider-physical-network provider --provider-network-type flat ext-net # 给外部网络绑定ip openstack subnet create --network ext-net --subnet-range 172.18.31.0/24 --gateway 172.18.31.1 --allocation-pool start=172.18.31.100,end=172.18.31.200 --dhcp ext-subnet # 创建int-net1(云主机子网 IP 可用网段为 10.0.0.100~10.0.0.200,网关为 10.0.0.1) openstack network create --internal int-net1 # 创建int-net1网段int-subnet1 openstack subnet create --subnet-range 10.0.0.0/24 --gateway 10.0.0.1 --dhcp --allocation-pool start=10.0.0.100,end=10.0.0.200 --network int-net1 int-subnet1 # 创建int-net2(云主机子网 IP 可用网段为 10.0.1.100 ~ 10.0.1.200,网关为 10.0.1.1) openstack network create --internal int-net2 # 创建int-net2网段 openstack subnet create --subnet-range 10.0.1.0/24 --gateway 10.0.1.1 --dhcp --allocation-pool start=10.0.1.100,end=10.0.1.200 --network int-net2 int-subnet2 # 添加路由ext-router openstack router create ext-router openstack router set --enable --enable-snat --external-gateway ext-net ext-router openstack router add subnet ext-router int-subnet1
7.搭建图形化界面 使用提供的脚本框架 iaas-install-dashboard.sh,填充脚本,在 controller 节点上安装 dashboard 服务并完成相关配置。
请使用 curl 指令获取 dashboard 首页信息,将获取到的首页信息提交到答 题框。【1 分】
controller
1 2 iaas-install-dashboard.sh curl -L http://192.168.100.10/dashboard
任务 3 OpenStack 运维任务 1.用户管理 在 keystone 中创建用户 testuser,密码为 password。创建好之后,使用命令修改 testuser 密码为 000000,并查看 testuser 的详细信息。添加将该 用户添加到 admin 项目并赋予普通用户权限,完成后测试登录。
使用 testuser 用登录系统完成后截图并提交到答题框。【1 分】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 openstack user create testuser --password password --domain demo openstack user set testuser --password 000000 openstack user show testuser +---------------------+----------------------------------+ | Field | Value | +---------------------+----------------------------------+ | domain_id | ff1e0a9d790046209bd22307ca565a8e | | enabled | True | | id | 79ab69675e6a454a83fc1f13bd884315 | | name | testuser | | options | {} | | password_expires_at | None | +---------------------+----------------------------------+ openstack role add user --user testuser --project admin
2.服务查询 使用命令列出服务目录和端点,查看 glance 服务的端点。将以上命令和返
回结果提交到答题框。【0.5 分】
1 2 3 openstack service list openstack endpoint list openstack endpoint list | grep glance
3.镜像管理 登录 controller 节点,使用 glance 相关命令,上传镜像,源使用 CentOS_6.5_x86_64_XD.qcow2,名字为 testone,然后使用 openstack 命令修改这个镜像名改为 examimage,然后给这个镜像打一个标签,标签名字为 lastone 改完后使用 openstack 命令查看镜像列表。
将以上命令和返回结果提交到答题框。【2 分】
1 2 3 glance image-create --name testone --disk-format qcow2 --container bare --file /opt/images/CentOS_6.5_x86_64_XD.qcow2 openstack image set --name examiage --tag lastone testone
4.后端配置文件管理 进入到glance 后端存储目录中,使用 qemu 命令查看任意的一个镜像信息。使用 du 命令查看 nova 主配置文件大小。
将以上命令和返回结果提交到答题框。【0.5 分】
1 2 3 cd /var/lib/glance/images/qemu-img info 6ca6669e-cc71-4f51-becf-b5db53c212f1
5.存储服务管理 创建一个卷类型,然后创建一块带这个卷类型标识的云硬盘,查询该云硬盘的详细信息。将该云硬盘挂载到虚拟机中,将该云硬盘格式化为 xfs。创建一个文件文件名为工位号内容为工位号,然后将该云硬盘卸载,使用 openstack 命令将该云硬盘修改为只读状态,再次挂载后查看是否存在原始文件,然后再次向该云硬盘中创建一个文件,文件名为工位号_02。
将返回结果及解题过程提交到答题框。【2 分】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #创建卷类型 openstack volume type create lvm1 #创建卷 openstack volume create --size 10 --type lvm1 juan1 #查看卷详细信息 openstack volume show juan1 #将云硬盘挂载到虚拟机中 openstack server add volume centos juan1 #将云硬盘格式化为xfs mkfs.xfs /dev/vdb #挂在创建文件 mount /dev/vdb /mnt touch /mnt/31 umount /mnt #云硬盘卸载 openstack server remove volume centos juan1 #设置为只读 openstack volume set juan1 --read-only #将云硬盘挂载到虚拟机中 openstack server add volume centos juan1 #挂在创建文件 mount /dev/vdb /mnt touch /mnt/31_02 显示不成功
6.存储服务管理 使用命令创建一个 5GB 的云硬盘,名称为 disk-2,将云硬盘挂载到云虚拟机内,然后格式化为 ext4,挂载到虚拟机的 /mnt/ 目录下,使用 df -h 将命令和返回信息提交到答题框。将该云硬盘使用命令卸载,使用命令将该云硬盘扩容到 10GB,使用命令将云硬盘挂载到云主机上,将命令及返回信息提交到答题框。进入云主机使用命令扩容文件系统,扩容后再次挂载到 /mnt/使用 df -hT 命令并将命令和返回信息提交到答题框。【2 分】。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 # 创建云硬盘 openstack volume create --size 5 'disk-2' # 挂载 openstack server add volume centos disk-2 # 格式化 mkfs.ext4 /dev/vdb mount /dev/vdb /mnt df-h # 卸载 umount /mnt openstack server remove volume centos disk-2 # 扩容 openstack volume set --size 10 'disk-2' # 挂载 openstack server add volume centos disk-2 # 格式化 mkfs.ext4 /dev/vdb mount /dev/vdb /mnt df -hT
7.对象存储管理 使用 swift 相关命令,创建一个容器,然后往这个容器中上传一个文件(文件可以自行创建),上传完毕后,使用命令查看容器。
将以上命令和返回结果提交到答题框。【0.5 分】
1 2 3 swift post container swift upload container /root/cirros-0.3.4-x86_64-disk.img swift list container
8.安全组管理 使用命令创建名称为 group_web 的安全组该安全组的描述为工位号,为该安全组添加一条规则允许任意 ip 地址访问 web 流量,完成后查看该安全组的详细信息。
将以上命令和返回结果提交到答题框。【2 分】
1 2 3 4 openstack security group create group_web --description 31 openstack security group rule create group_web --protocol tcp --dst-port 80:80 --remote-ip 0.0.0.0/0 openstack security group rule create group_web --protocol tcp --dst-port 443:443 --remote-ip 0.0.0.0/0 openstack security group show group_web
9.网络管理 使用命令将int-net1网络设置为共享,然后查看int-net1网络的详细信息。
将命令和返回信息提交到答题框。
1 openstack network set --share int-net1
10.网络管理 使用 dashboard 界面使用 centos7.5 镜像创建一台云主机,云主机命名为 test-01,使用命令查看浮动 IP 地址池,使用命令创建一个浮动 IP,然后将浮动IP 绑定到云主机上。
将命令和返回信息提交到答题框。【1 分】
1 2 openstack floating ip create ext-net openstack server add floating ip test-01 172.18.31.118
11.虚拟机管理 使用 opentack 命令利用 centos7.5 镜像创建一台云主机,连接 int-net1 网 络,云主机名称为 test-02。创建成功后使用命令查看云主机详细信息,确定该云主机是处于计算节点还是控制节点。如果云主机处于控制节点上请将其冷迁移到计算节点,如果如果云主机处于计算节点上请将其冷迁移到控制节点。
本题全部流程请使用命令完成,请将全部命令和结果粘贴到答题框。【3 分】
一、冷迁移 1、在控制节点关闭虚拟机 2、在计算节点找到实例位置(/var/lib/nova/instances) 3、将计算节点的需要转移的实例文件copy到目标主机的相同位置下。 4、到目标主机,赋予实例权限 5、登录数据库更改mysql的host,node字段为新的物理主机名。 6、重启目标主机的nova-compute服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 # 查看虚拟机在哪个节点 openstack service show test-02 # 停止准备迁移的主机 openstack server stop test-02 # 迁移 cd /var/lib/nova/instances/ scp 1f03d8ae-1190-49b5-9590-c7bee2912f69/ root@172.17.31.10:/var/lib/nova/instances/ # 登录并赋予权限 cd /var/lib/nova/instances/ chown nova:nova 1f03d8ae-1190-49b5-9590-c7bee2912f69/ -R # 登录mysql(根据虚拟机位置更改,登录数据库更改MySQL中的host、node字段为新的物理主机名字) mysql -uroot -p > use nova; update instances set host='controller', node='controller' where uuid='1f03d8ae-1190-49b5-9590-c7bee2912f69'; > exit # 重启节点 systemctl restart openstack-nova-compute.service
B 场次题目:容器的编排与运维
任务 1 容器云平台环境初始化 1.容器云平台的初始化 根据表 2 的 IP 地址规划,创建云服务器,镜像使用CentOS_7.5_x86_64_XD.qcow,确保网络正常通信。按照表 2 置主机名节点并关闭 swap,同时永久关闭 selinux 以及防火墙,并修改 hosts 映射。
请将 master 节点 hosts 文件内容提交到答题框。【1 分】
Master
1 2 3 4 5 6 7 8 9 10 11 12 hostnamectl set-hostname master setenforce 0 vi /etc/selinux/config SELINUX=disabled swapoff -a systemctl stop firewalld systemctl disable firewalld vi /etc/hosts 10.0.0.1/24 master 10.0.0.2/24 node1 10.0.0.3/24 node2 10.0.0.4/24 harbor
Node1
1 2 3 4 5 6 7 8 hostnamectl set-hostname node1 setenforce 0 vi /etc/selinux/config SELINUX=disabled swapoff -a systemctl stop firewalld systemctl disable firewalld
Node2
1 2 3 4 5 6 7 8 hostnamectl set-hostname node2 setenforce 0 vi /etc/selinux/config SELINUX=disabled swapoff -a systemctl stop firewalld systemctl disable firewalld
Harbor
1 2 3 4 5 6 7 8 hostnamectl set-hostname habor setenforce 0 vi /etc/selinux/config SELINUX=disabled swapoff -a systemctl stop firewalld systemctl disable firewalld
2.Yum源数据的持久化挂载 将提供的 CentOS-7-x86_64-DVD-1804.iso 和 chinaskills_cloud_paas.iso 光盘镜像上传到 master 节点 /root 目录下,然后在 /opt 目录下使用命令创建/centos 目录和 /paas 目录,并将镜像文件 CentOS-7-x86_64-DVD-1804.iso 挂载到/centos 目录下,将镜像文件 chinaskills_cloud_paas.iso 挂载到 /paas目录下。请设置永久开机自动挂载,并将设置的永久开机自动挂载的文件内容提交到+答题框。【1 分】
Master
1 2 3 4 5 6 7 8 9 10 mkdir /opt/centos mkdir /opt/paas mount CentOS-7-x86_64-DVD-1804.iso /opt/centos mount chinaskills_cloud_paas.iso /opt/paas vi /etc/fstab /root/CentOS-7-x86_64-DVD-1804.iso /opt/centos iso9660 defaults 0 0 /root/chinaskills_cloud_paas.iso /opt/paas iso9660 defaults 0 0 mount -a
3.Yum源的编写 为 master 节点设置本地 yum 源,yum 源文件名为 centos.repo,安装 ftp 服务,将 ftp 仓库设置为 /opt/,为其他节点配置 ftp 源,yum 源文件名称为 ftp.repo,其中 ftp 服务器地址为 master 节点 IP。
请将其它节点的 yum 源文件内容提交到答题框。【1 分】
Master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 mv /etc/yum.repos.d/* /etc/yum vi /etc/yum.repos.d/centos.repo [centos] name=centos baseurl=file:///opt/centos gpgcheck=0 enabled=1 [k8s] name=k8s baseurl=file:///opt/paas/kubernetes-repo gpgcheck=0 enabled=1 # 安装vsftpd服务 yum install -y vsftpd vi /etc/vsftpd/vsftpd.conf anon_root=/opt/ systemctl start vsftpd systemctl enable vsftpd iptables -F iptables -X iptables -Z /usr/sbin/iptables-save
其他节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 mv /etc/yum.repos.d/* /etc/yum vi /etc/yum.repos.d/ftp.repo [centos] name=centos baseurl=ftp://10.0.0.1/centos gpgcheck=0 enabled=1 [k8s] name=k8s baseurl=ftp://10.0.0.1/paas/kubernetes-repo gpgcheck=0 enabled=1 iptables -F iptables -X iptables -Z /usr/sbin/iptables-save
4.设置时间同步服务器 在 master 节点上部署 chrony 服务器,允许其他节点同步时间,启动服务并设置为开机启动;在其他节点上指定 master 节点为上游 NTP 服务器,重启服务并设为开机启动。
请在 master 节点上使用 chronyc 命令同步控制节点的系统时间。【1 分】
Master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # server 0.centos.pool.ntp.org iburst # server 1.centos.pool.ntp.org iburst # server 2.centos.pool.ntp.org iburst # server 3.centos.pool.ntp.org iburst server master iburst # Record the rate at which the system clock gains/losses time . driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second.makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. # hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. # minsources 2 # Allow NTP client access from local network. # allow 192.168.0.0/16 # Serve time even if not synchronized to a time source . # local stratum 10# Specify file containing keys for NTP authentication. # keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. # log measurements statistics trackingallow 10.0.0.0/24 local stratum 10 systemctl restart chronyd systemctl enable chronyd
其他节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 vi /etc/chrony.conf # Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). # server 0.centos.pool.ntp.org iburst # server 1.centos.pool.ntp.org iburst # server 2.centos.pool.ntp.org iburst # server 3.centos.pool.ntp.org iburst server master iburst # Record the rate at which the system clock gains/losses time . driftfile /var/lib/chrony/drift # Allow the system clock to be stepped in the first three updates # if its offset is larger than 1 second.makestep 1.0 3 # Enable kernel synchronization of the real-time clock (RTC). rtcsync # Enable hardware timestamping on all interfaces that support it. # hwtimestamp * # Increase the minimum number of selectable sources required to adjust # the system clock. # minsources 2 # Allow NTP client access from local network. # allow 192.168.0.0/16 # Serve time even if not synchronized to a time source . # local stratum 10# Specify file containing keys for NTP authentication. # keyfile /etc/chrony.keys # Specify directory for log files. logdir /var/log/chrony # Select which information is logged. # log measurements statistics trackingsystemctl restart chronyd systemctl enable chronyd
5.设置免密登录 为四台服务器设置免密登录,保证 3 台服务器能够互相免密登录。请使用 scp 命令将 master 节点的 hosts 文件发送到所有节点的 /etc/hosts。将以上所有命令和返回结果提交到答题框。【1 分】
Master
1 2 3 4 5 6 7 8 ssh-keygen ssh-copy-id root@10.0.0.2 ssh-copy-id root@10.0.0.3 ssh-copy-id root@10.0.0.4 scp /etc/hosts root@10.0.0.2:/etc/hosts scp /etc/hosts root@10.0.0.3:/etc/hosts scp /etc/hosts root@10.0.0.4:/etc/hosts
任务 2 Kubernetes 搭建任务(10 分) 1.安装docker应用 在所有节点上安装 dokcer-ce。并在 harbor 节点安装 harbor 仓库,显现正常登录 horbor 仓库,登录密码设置为“test_工位号”。请将登录后截图提交到
答题框。【1 分】
所有节点
1 2 3 4 5 6 7 # 安装依赖 yum install -y yum-utils lvm2 device-mapper-* # 安装docker-ce yum install -y docker-ce systemctl start docker systemctl enable docker
Harbor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # 安装docker-compose cp -rfv /opt/docker-compose/v1.25.5-docker-compose-Linux-x86_64 /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose version # 安装harbor tar -zxvf harbor-offline-installer-v2.1.0.tgz cd harbor cp harbor.yml.tmpl harbor.yml vi harbor.yml hostname: 10.0.0.4 # 将域名修改为本机IP harbor_admin_password: test_31 ./prepare ./install.sh --with-clair
2.搭建harbor仓库 修改默认 docker 仓库为 horbor 地址,修改 docker 启动引擎为 systemd。安装完成后执行 docker verison 命令返回结果以及将 daemon.json 文件内容提交。【2 分】
所有节点
1 2 3 4 5 6 7 8 9 tee /etc/docker/daemon.json <<'EOF' { "insecure-registries" : ["10.0.0.4:5000" ], "exec-opts" : ["native.cgroupdriver=systemd" ] } EOF systemctl restart docker docker version
3.安装 docker-compose 在 master 节点上使用 /opt/paas/docker-compose/v1.25.5-docker-compose-Linux-x86_6 下的文件安装 docker-compose。安装完成后执行 docker-compose version 命令,请将程序返回结果提交到答题框。【0.5 分】
Master
1 2 3 cp -rfv /opt/docker-compose/v1.25.5-docker-compose-Linux-x86_64 /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose version
4.上传docker镜像 在 master 节点使用 /opt/paas/ k8s_image_push.sh 将所有镜像上传至 docker 仓库。完成后将 Harbor 仓库 library 中镜像列表截图,请将以上截图提交到答题框。【1 分】
①.创建CA证书 (harbor)
1 2 3 4 5 6 mkdir /cert/ -pcd /cert/ openssl req -newkey rsa:4096 -nodes -sha256 -keyout ca.key -x509 -days 365 -out ca.crt Common Name (eg, your name or your server's hostname) []:10.0.0.4
②.生成证书签名请求
1 2 3 openssl req -newkey rsa:4096 -nodes -sha256 -keyout 10.0.0.4.key -out 10.0.0.4.csr 一路回车出现Common Name 输入IP或域名 Common Name (eg, your name or your server's hostname) []:10.0.0.4
③生成证书
1 2 echo subjectAltName = IP:10.0.0.4 > extfile.cnfopenssl x509 -req -days 365 -in 10.0.0.4.csr -CA ca.crt -CAkey ca.key -CAcreateserial -extfile extfile.cnf -out 10.0.0.4.crt
④配置harbor.yml
1 2 3 4 5 6 tar -zxvf harbor-offline-installer-v2.0.1.tgz cd harborcp harbor.yml.tmpl harbor.ymlhostname=10.0.0.4 ssl_cert = /cert/10.0.0.4.crt ssl_cert_key = /cert/10.0.0.4.key
⑤配置使用harbor
因为是自签证书需要添加到信任
每一个客户端都需要复制上面的ca.crt到Docker相应目录,然后重启Docker。
1 2 3 mkdir –p /etc/docker/certs.d/10.0.0.4 cp ca.crt /etc/docker/certs.d/10.0.0.4/ca.crt systemctl restart docker
注意:
1 2 3 4 5 # 在使用k8s_image_pull.sh可能不成功 原因一:前面的k8s_harbor_install中有一个命令未使用 for i in $(ls /opt/images|grep tar); do docker load -i /opt/images/$i done 原因二:目录不正确,需要更改目录 /opt(按题目叙述)
5.安装 kubeadm 工具 在 master 及 node 节点安装 Kubeadm 工具并设置开机自动启动,安装完成后使用 rpm 命令配合 grep 查看 Kubeadm 工具是否正确安装。
将 rpm 命令配合 grep返回结果提交到答题框。【0.5 分】
1 2 3 4 5 yum -y install kubeadm-1.18.1 kubectl-1.18.1 kubelet-1.18.1 systemctl enable kubelet && systemctl start kubelet rpm -qa | grep ku
6.计算节点获取必备镜像 在所有 node 节点中使用 docker 命令拉取安装 kubernetes 基础镜像,拉取完成后使用 docker 命令查看镜像列表。【1 分】
1 2 docker pull ... docker images
7.kubeadm 安装 master 使用 kubeadm 命令初始化 master 节点,设置 kubernetes 虚拟内部网段地址为 10.244.0.0/16,然后使用 kube-flannel.yaml 完成控制节点初始化设置,完成后使用命令查看集群状态和所有 pod。
将以上命令和返回结果提交到答题框。【2 分】
master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 cat >> /etc/sysctl.d/k8s.conf <<EOF net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system //生效 kubeadm init --apiserver-advertise-address=192.168.200.162 --kubernetes-version="v1.18.0" --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers --service-cidr=10.96.0.0/12 kubectl apply -f kube-flannel.yaml kubectl get pod -A kubectl get cs
8.安装 kubernetes 网络插件 使用 kube-flannel.yaml 安装 kubernetes 网络插件,安装完成后使用命令查看节点状态。完成后使用命令查看集群状态。将集群状态查看命令和返回结果
提交到答题框。【0.5 分】
9.kubernetes 图形化界面的安装 安装 kubernetes dashboard 界面,完成后查看首页然后将 kubernetes dashboard 界面截图提交到答题框。【1 分】
①创建证书
1 2 3 4 5 6 7 8 mkdir dashboard-certs cd dashboard-certs/ kubectl create namespace kubernetes-dashboard openssl genrsa -out dashboard.key 2048 openssl req -days 36000 -new -out dashboard.csr -key dashboard.key -subj '/CN=dashboard-cert' openssl x509 -req -in dashboard.csr -signkey dashboard.key -out dashboard.crt kubectl create secret generic kubernetes-dashboard-certs --from-file=dashboard.key --from-file=dashboard.crt -n kubernetes-dashboard
②安装dashboard
1 2 3 4 5 kubectl apply -f recommended.yaml # 查看状态 kubectl get pod,svc -n kubernetes-dashboard kubectl apply -f dashboard-adminuser.yaml
访问dashboard(https://IP:30000)
获取token
1 2 kuebctl get secret -n kubernetes-dashboard kubectl describe secret -n kubernetes-dashboard <sec名称>
10.扩展计算节点 在 master 节点上使用 kubeadm 命令查看 token,在所有 node 节点上使用 kubeadm 命令将 node 节点加入 kubernetes 集群。完成后在 master 节点上查看所有节点状态。将集群状态查看命令和返回结果提交到答题框。【0.5 分】
1 2 3 4 5 6 7 # 查看token kubeadm token list # 查看--discovery-token-ca-cert-hash值 openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //' kubeadm join 192.168.200.162:6443 --token qi3pfd.mv5s93kio6jb4m7s \ --discovery-token-ca-cert-hash sha256:c559bb4420ee1e071655498290a39fd4e0a0126c239b3be7cb1065b5b9f971d5
任务 3 Kubernetes 运维任务(15 分) 1.使用 dockerfile 构建 dokcer 镜像 以 mysql:5.7 镜像为基础镜像,制作一个 mysql 镜像,可以将提供的 sql 文件初始化到 mysql 数据库中,然后使用编写的 dockerfile 文件将镜像制作出来,名称为 mysql:latest,并将该镜像上传至前面所搭建的 harbor 仓库中,编写 YAML 文件,验证数据库内容。
master
1 2 3 4 5 6 7 8 vi Dockerfile FROM mysql:5.7 MAINTAINER ywj WORKDIR /docker-entrypoint-initdb.d ENV MYSQL_ROOT_PASSWORD=123456 COPY gpmall.sql /opt/sql/ COPY init.sql /docker-entrypoint-initdb.d/
1 2 3 4 5 6 init.sql grant all on *.* to 'root'@'%' identified by '123456'; create database gpmall default character set=utf8; use gpmall; source /opt/sql/gpmall.sql;
将sql文件放在本目录中
2.持久化存储 搭建 NFS 共享存储,配置 nfs-provisioner,创建 storageclass,通过 storageclass 动态生成 pvc,大小为 1Gi,修改标准 nfs-deployment.yaml 文件,编写 storageclass.yaml 和 pvc.yaml 文件,将最终 pvc 状态截图和 yaml 文件提
交至答题框。【2 分】
部署流程
创建一个可用的NFS Server
创建Service Account,这是用来管控NFS Provisioner 在k8s集群中运行的权限
创建StorageClass,负责建立PVC并调用NFS provisioner进行预定的工作,并让PV与PVC建立关联
创建NFS provisioner,有两个功能,一个是在NFS共享目录下创建挂载点(volume),另一个则是建了PV并将PV与NFS的挂载点建立关联
安装nfs-server,并完成配置
1 2 3 4 5 6 7 8 9 10 11 yum install -y nfs-utils rpcbind yum install -y nfs-utils(不要启动) vi /etc/exports /nfsdata *(rw,sync ,no_root_squash,no_subtree_check) systemctl start nfs-server rpcbind systemctl enable nfs-server rpcbind showmount -e
编写serviceaccount.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 apiVersion: v1 kind: ServiceAccount metadata: name: nfs-client-provisioner namespace: demo --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: nfs-client-provisioner-runner rules: - apiGroups: ["" ] resources: ["nodes" ] verbs: ["get" , "list" , "watch" ] - apiGroups: ["" ] resources: ["persistentvolumes" ] verbs: ["get" , "list" , "watch" , "create" , "delete" ] - apiGroups: ["" ] resources: ["persistentvolumeclaims" ] verbs: ["get" , "list" , "watch" , "update" ] - apiGroups: ["storage.k8s.io" ] resources: ["storageclasses" ] verbs: ["get" , "list" , "watch" ] - apiGroups: ["" ] resources: ["events" ] verbs: ["create" , "update" , "patch" ] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: run-nfs-client-provisioner subjects: - kind: ServiceAccount name: nfs-client-provisioner namespace: demo roleRef: kind: ClusterRole name: nfs-client-provisioner-runner apiGroup: rbac.authorization.k8s.io --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: leader-locking-nfs-client-provisioner namespace: demo rules: - apiGroups: ["" ] resources: ["endpoints" ] verbs: ["get" , "list" , "watch" , "create" , "update" , "patch" ] --- kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: leader-locking-nfs-client-provisioner namespace: demo subjects: - kind: ServiceAccount name: nfs-client-provisioner namespace: demo roleRef: kind: Role name: leader-locking-nfs-client-provisioner apiGroup: rbac.authorization.k8s.io
编写stroageclass.yaml
1 2 3 4 5 6 7 8 9 10 apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: managed-nfs-storage annotations: storageclass.kubernetes.io/is-default-class: "true" provisioner: k8s/nfs-subdir-external-provisioner allowVolumeExpansion: true parameters: archiveOnDelete: "false"
编写nfs-deployment.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 apiVersion: apps/v1 kind: Deployment metadata: name: nfs-client-provisioner labels: app: nfs-client-provisioner namespace: demo spec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: nfs-client-provisioner template: metadata: labels: app: nfs-client-provisioner spec: nodeName: master tolerations: - key: node-role.kubernetes.io/master operator: Equal value: "true" serviceAccountName: nfs-client-provisioner containers: - name: nfs-client-provisioner image: 192.168 .200 .165 /library/nfs-client-provisioner@sha256:4c16495be5b893efea1c810e8451c71e1c58f076494676cae2ecab3a382b6ed0 imagePullPolicy: IfNotPresent volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: k8s/nfs-subdir-external-provisioner - name: NFS_SERVER value: 192.168 .200 .162 - name: NFS_PATH value: /nfsdata volumes: - name: nfs-client-root nfs: server: 192.168 .200 .162 path: /nfsdata
编写pvc.yaml
1 2 3 4 5 6 7 8 9 10 apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nfs-claim spec: storageClassName: managed-nfs-storage accessModes: ["ReadWriteMany" ,"ReadOnlyMany" ] resources: requests: storage: 1Gi
3.编写deployment.yaml文件 将提供的 nginx:latest 镜像上传至 harbor 镜像仓库,使用该镜像编写 deployment 文件,要求将已创建的 pvc 挂载至/html 目录下,副本数 1,实现资源限制:需求内存 300Mi,需求 CPU 300M,限制内存 450Mi,限制 CPU450M,将 POD 状态截图和 yaml 文件提交至答题框。【3 分】
1 2 #若报错请删除污点 kubectl taint nodes master node-role.kubernetes.io/master-
nginx.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: default spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: 10.0 .0 .1 /library/nginx@sha256:416d511ffa63777489af47f250b70d1570e428b67666567085f2bece3571ad83 volumeMounts: - name: nfs-pv mountPath: /html resources: limits: cpu: 450m memory: 450Mi requests: cpu: 300m memory: 300Mi volumes: - name: nfs-pv persistentVolumeClaim: claimName: nfs-claim
4.创建 service 服务,提供对外访问接口 基于 nginx 的 pod 服务,编写一个 service 名称为 nginx-svc,代理 nginx的服务端口,端口类型为 nodeport,创建成功后可以通过该 service 访问 nginx。
完成后提交 yaml 文件及访问截图至答题框。【3 分】
1 2 3 4 5 6 7 8 9 10 11 12 apiVersion: v1 kind: Service metadata: name: nginx-svc namespace: default spec: selector: app: nginx type: NodePort ports: - port: 80 targetPort: 80
5.配置 metrics-server 实现资源监控 将已提供的 metrics-server 镜像上传至 harbor,修改 components.yaml,创建 metrics-server,完成后,将 metrics-server 状态截图提交至答题框。【2分】
1、修改配置
1 2 3 4 5 6 7 8 9 10 11 12 ps -ef |grep apiserver|grep true vi /etc/kubernetes/manifests/kube-apiserver.yaml - --enable-aggregator-routing=true vi metrics-server-0.3.6/deploy/1.8+/metrics-server-deployment.yaml args: - /metrics-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalIP
2.启动服务
1 2 cd /root/metrics-server-0.3.6/deploy/1.8+ kubectl apply -f .
6.配置弹性伸缩 编写 deployment-nginx-hpa.yaml 文件,要求最小副本数 1,最大副本数 3,当整体的资源利用率超过 80%的时候实现自动扩容,将 yaml 文件提交至答题框。【2 分】
deployment-nginx-hpa.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: nginx-hpa namespace: default spec: maxReplicas: 3 minReplicas: 1 targetCPUUtilizationPercentage: 80 scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: nginx
7.压力测试 安装 httpd-tools 工具,通过 service 提供的对外访问接口进行压力测试,验证 HPA 弹性伸缩功能,将 HPA 状态和 POD 状态截图提交至答题框。【2 分】
1 2 3 4 yum install -y httpd-tools ab -n 1000 -c 100 https://www.baidu.com/ 表请求1000次中有100并发
C 场次题目:企业级应用的自动化部署和运维
任务 1 企业级应用的自动化部署(15 分) 1. ansible 自动化运维工具的安装【3 分】 请使用提供的软件包在 master 节点安装 ansible,安装完成后使用 ansible –version 命令验证是否安装成功。为所有节点添加 test 用户,设置用户密码为 000000。为 test 用户设置免密 sudo,配置 ssh 免密登录,使 master 节点能够免密登录所有节点的 test 用户。
将 ansible –version 命令和回显粘贴到答题框。
master
1 2 3 4 5 6 yum install -y jinja2 PyYAML cryptography rpm -ivh ansible-2.4.6.0-1.el7.ans.noarch.rpm ansible --version
全部节点
1 2 3 4 5 useradd test passwd test visudo test ALL=(ALL) NOPASSWD:ALL
master
1 2 3 4 ssh-keygen ssh-copy-id test @192.168.200.100 ssh-copy-id test @192.168.200.101 ssh-copy-id test @192.168.200.102
2.ansible 自动化运维工具的初始化【3 分】 创建 /root/ansible 目录作为工作目录,在该目录内创建 ansible.cfg 文件并完成以下配置,清单文件位置为 /root/ansible/inventory,登录用户为 test,登录时不需要输入密码。设置并行主机数量为 2,允许 test 用户免密提权到 root。
将 ansible.cfg 文件内容粘贴到答题框。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 mkdir /root/ansiblevi ansible.cfg [defaults] inventory=./inventory forks=2 remote_user=test ask_pass=false [privilege_escalation] become=true become_user=root become_ask_pass=false [defaults] inventory=./inventory forks=2 remote_user=test ask_pass=false [privilege_escalation] become=true become_method=sudo become_user=root become_ask_pass=false
3.主机清单的编写【2分】 编写主机清单文件,创建 master 用户组,master 用户组内添加 master 主机;创建 node 用户组,node 组内添加 node1 和 node2 主机,主机名不得使用 IP 地址。
完成后执行 ansible-inventory –list 、ansible all -m ping 和 ansible all -a “id” 命令,将这三条命令返回结果粘贴到答题框。
1 2 3 4 5 6 7 vi inventory [master] master [node] node1 node2
4.使用自动化工具对 master 节点进行初始化【2 分】 请编写 prometheus.yml 控制 master 主机组,使用对应模块将 SELinux 临时状态和开机启动状态也设置为 disabled。请使用 ansible 对应模块安装时间同步服务,使用文本编辑模块将该服务的作用域设置为 0.0.0.0/0,并设置状态为启动和开机自动启动。首先将提供的 prometheus-2.37.0.linux-amd64.tar.gz 使用文件拷贝模块将该压缩包拷贝到目标主机的/usr/local/ 下,使用 shell 模块解压该压缩包。
完成后提交 yml 文件和和 ansible 运行结果。
vi prometheus.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 - hosts: master remote_user: root tasks: - name: SELINUX=disabled selinux: state=disabled - name: stop firewalld shell: 'sudo systemctl stop firewalld && sudo systemctl disable firewalld' - name: install chrony yum: name=chrony state=present - name: allow 0.0 .0 .0 /0 blockinfile: path=/etc/chrony.conf block="allow 0.0 .0 .0 /0" - name: start chrony service: name=chronyd state=started enabled=yes - name: copy promethus copy: src=/root/prometheus-2.37.0.linux-amd64.tar.gz dest=/usr/local/ - name: tar prometheus shell: 'sudo tar -zxvf /usr/local/prometheus-2.37.0.linux-amd64.tar.gz -C /usr/local'
5.使用自动化运维工具完成企业级应用的部署【5 分】 编写 prometheus.yml.j2 模板文件,将所有 node 节点信息添加到该文件中,但是被管节点的主机名信息必须使用变量 IP 地址可以手动输入。完成后请创建node_exporter.yml 文件,编写第一个 play,将该 play 命名为 node,该 play控制的主机组为 node。使用 ansible 模块将 node_exporter-1.3.1.linux-amd64.tar.gz 发送到 node 主机组的 /usr/local/ 下,使用一个 shell 模块解压该压缩包,并启动该服务。随后编写第二个 play,将第二个 play 命名为 master,第二个 play 控制 master 节点。首先使用 ansible 模块将 prometheus.yml.j2 文件传输到 master 节点,然后使用 script 模块将 prometheus 启动。使用对应模块将 grafana-8.1.2-1.x86_64.rpm 包发送到被控节点的 /mnt/ 目录下,然后使用对应模块将该软件包安装,安装完成后设置 grafana 服务启动并设置开机自动启动。使用浏览器登录 prometheus 查看 prometheus 是否成功监控所有 node 节点。
请将浏览器反馈的结果截图、prometheus.yml.j2 文件的内容、node_exporter.yml 文件内容及运行结果提交到答题框。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 --- - hosts: node name: node tasks: - name: copy node_expose copy: src=/root/node_exporter-1.3.1.linux-amd64.tar.gz dest=/usr/local/ - name: tar node_expose shell: 'sudo tar -zxvf /usr/local/node_exporter-1.3.1.linux-amd64.tar.gz -C /usr/local/' - name: start node_export shell: 'sudo nohup /usr/local/node_exporter-1.3.1.linux-amd64/node_exporter &' - hosts: master name: master vars: node1: 192.168 .200 .101 node2: 192.168 .200 .102 tasks: - name: template j2 template: src=./prometheus.yml.j2 dest=/usr/local/prometheus-2.37.0.linux-amd64/prometheus.yml - name: start prometheus shell: 'sudo nohup /usr/local/prometheus-2.37.0.linux-amd64/prometheus &' - name: copy grafana copy: src=/root/grafana-8.1.2-1.x86_64.rpm dest=/mnt/ - name: install repaired shell: 'sudo yum install -y fontconfig urw-fonts ' - name: install grafana shell: 'sudo rpm -ivh /mnt/grafana-8.1.2-1.x86_64.rpm' - name: enable gtafana service: name=grafana-server state=started enabled=yes
prometheus.j2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 global: scrape_interval: 15s evaluation_interval: 15s alerting: alertmanagers: - static_configs: - targets: rule_files: scrape_configs: - job_name: "prometheus" static_configs: - targets: ["localhost:9090" ] - job_name: "node_exposed" static_configs: - targets: ["{{node1}} :9100" ,"{{node2}} :9100" ]
任务 2 企业级应用的运维(12 分) 1.使用 prometheus 监控 mysqld 服务【3 分】 将提供的 mysqld_exporter-0.14.0.linux-amd64.tar.gz 发送到 agent 虚拟机 /usr/local/ 目录下解压并安装 mariadb 服务。进入 mariadb 数据库中创建 mysqld_monitor 用户并授权,然后创建 mariadb 配置文件,内容为数据库用户名密码。启动 mysqld_exporter 组件确保 9104 端口启动。回到 prometheus 节点修改 prometheus.yml 文件并添加 mysql 被监控信息。重启 prometheus,随后web 界面刷新并查看 mysqld 被控信息。
将以上操作提交到答题框。
vi mysqld_exporter.yml
1 2 3 4 5 6 7 8 9 10 11 12 --- - hosts: node name: node tasks: - name: copy mysqld_exporter copy: src=/root/mysqld_exporter-0.14.0.linux-amd64.tar.gz dest=/usr/local/ - name: tar it shell: 'sudo tar -zxvf /usr/local/mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local' - name: anzhuang mariadb shell: 'sudo yum install -y mariadb*' - name: start mysqld service: name=mariadb state=started enabled=yes
在agent节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 mysql >grant select ,replication client,process ON *.* to 'mysql_monitor' @'localhost' identified by '123' ; >flush privileges; > quit vi /usr/local/mysqld_exporter-0.14.0.linux-amd64/.my.cnf [client] user=mysql_monitor password=123 nohup /usr/local/mysqld_exporter-0.14.0.linux-amd64/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter-0.14.0.linux-amd64/.my.cnf &netstat -nltp | grep 9104
回到master节点
1 2 3 4 5 6 7 8 9 vi /usr/local/prometheus-2.37.0.linux-amd64/prometheus.yml - job_name: 'mysql' static_configs: - targets: ['node1:9104' ,'node2:9104' ] pkill prometheus nohup /usr/local/prometheus-2.37.0.linux-amd64/prometheus &
2.安装altermanager报警组件 将提供的alertmanager-0.21.0.linux-amd64.tar.gz上传到prometheus节点 /usr/local/ 目录下并解压,创建软连接 alertmanager-0.23.0.linux-amd64/ alertmanager。创建 service 启动文件,然后启动 alertmanager 查看 9093端口。在 prometheus.yml 配置文件中添加 alertmanager 信息并重新启动 prometheus 服务,在 agent 上停止 node_exporter 服务。到 web 界面中查看警报管理器状态是否正常和 agent 状态是否异常。
将操作命令及截图提交到答题框。
prometheus节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 tar -zxvf alertmanager-0.21.0.linux-amd64.tar.gz -C /usr/local/ ln -s alertmanager-0.23.0.linux-amd64/ alertmanagervi /usr/lib/systemd/system/alertmanager.service [Unit] Description=alertmanager [Service] ExecStart=/usr/local/alertmanager-0.21.0.linux-amd64/alertmanager --config.file=/usr/local/alertmanager-0.21.0.linux-amd64/alertmanager.yml ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure [Install] WantedBy=multi-user.target systemctl daemon-reload systemctl start alertmanager - job_name: 'altermanager' static_configs: - targets: ['localhost:9093' ] pkill prometheus nohup /usr/local/prometheus/prometheus.yml &
agent:
1 2 pkill node_exporter nohup /usr/local/node_exporter-1.3.1.linux-amd64/node_exporter &
3.alertmanager 告警邮件文件编写【3 分】 Prometheus 虚拟机 /usr/local/alertmanager/ 中存在着一个 alertmanager.yml 文件,请根据提供的地址和模板编写告警所发送到的 email 邮箱地址信息。
将配置文件中编写的内容提交到答题框。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 smtp_auth_username: "1234567890@qq.com" smtp_auth_password: "auth_pass" smtp_require_tls: false route: receiver: ops group_wait: 30s group_interval: 5m repeat_interval: 24h group_by: [alertname ] routes: - match: team: operations group_by: [env ,dc ] receiver: 'ops' - receiver: ops group_wait: 10s match: team: operations receivers: - name: ops email_configs: - to: '9935226@qq.com,xxxxx@qq.com' send_resolved: true headers: from: "警报中心" subject: "[operations] 报警邮件" to: "小煜狼皇"
4.alertmanager 告警规则编写【3 分】 在 prometheus 虚拟机的 prometheus 路径下存在一个 /rules 目录,目录下有一个 node_rules.yml 文件。请根据提供信息仿照模板编写:(1)内存大于 50%报警规则;
(2)cpu 资源利用率大于 75%报警规则;
(3)主机磁盘每秒读取数据>50MB%报警规则;
部门名称可为工位号,将配置文件内容提交到答题框。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 groups: - name: node_health rules: - alert: HighMemoryUsage expr: node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes < 0.5 for: 1m labels: severity: warning annotations: summary: High memory usage - alert: HighCPUUseage expr: 1 -sum(increase(node_cpu_seconds_total{mode="idle"}[1m])) by (instance) / sum(increase(node_cpu_seconds_total[1m])) by (instance) > 0.75 for: 1m labels: severity: warning annotations: summary: High CPU usage - alert: HighReadTime expr: sum(irate(node_disk_read_bytes_total[1m])) by (instance) > 50 for: 1m labels: severity: warning annotations: summary: High Read Time
任务3 企业级微服务运维(13 分) 1.在 Kubernetes 集群安装 istio【4 分】 一定要先安装mertics
将 istio-1.10.1-linux-amd64.tar 上传至 master 节点并解压至/root 目录下,将 /istio 目录内容器镜像文件上传至各 node 节点中并且加载,完成 istio 初始化安装,将部署成功后三台 POD 状态截图提交答题框。
1 2 3 4 5 6 7 8 9 10 11 12 13 tar -zxvf istio-1.10.1-linux-amd64.tar cd istio-1.10.1/ cp bin/istionctl /usr/local/bin # 通过istioctl安装istio istioctl install --set profile=demo This will install the Istio 1.13.4 demo profile with ["Istio core" "Istiod" "Ingress gateways" "Egress gateways"] components into the cluster. Proceed? (y/N) y ✔ Istio core installed ✔ Istiod installed ✔ Egress gateways installed ✔ Ingress gateways installed ✔ Installation complete Making this installation the default for injection and validation.
完成安装后查看相应服务是否成功启动
1 2 3 4 5 kubectl get pod -n istio-system NAME READY STATUS RESTARTS AGE istio-egressgateway-5dc6c98fbc-vdlml 1/1 Running 0 3d1h istio-ingressgateway-87bbdd549-8776n 1/1 Running 0 3d1h istiod-56b7b78cb5-94c69 1/1 Running 0 3d1h
2.部署基于在线书店 bookinfo【6 分】 Bookinfo 是一个在线书店微服务应用,Bookinfo 应用分为四个单独的微
服务:
(1)productpage。这个微服务会调用 details 和 reviews 两个微服务,用来生成页面。
(2)details。 这个微服务中包含了书籍的信息。
(3)reviews。这个微服务中包含了书籍相关的评论。它还会调用 ratings 微服务。
(4)ratings。这个微服务中包含了由书籍评价组成的评级信息。reviews 微服务有 3 个版本:v1 版本不会调用 ratings 服务;v2 版本会 调用 ratings 服务,并使用 1 到 5 个黑色星形图标来显示评分信息;v3 版本会调用 ratings 服务,并使用 1 到 5 个红色星形图标来显示评分信息。实现该应用服务网格的部署,利用 Istio 控制平面为应用提供服务路由、 监控数据收集以及策略实施等功能。部署架构如下:
(1)编写 Dockerfile 构建 productpage:v1.0 镜像,具体要求如下:
基础镜像:centos:7.9.2009;
安装 Python3.6.8 工具;
安装 productpage 服务并设置开机自启
(2)规划应用微服务部署架构,在容器集群中通过修改微服务应用的 yaml
文件来完成 bookinfo 微服务应用的部署。
边车注入(手动注入)
1 istioctl kube-inject -f samples/bookinfo/platform/kube/bookinfo.yaml -o samples/bookinfo/platform/kube/bookinfo-istio.yaml
(3)在容器集群中设置熔断规则,对 Bookinfo 其中的 productpage 微服务设置熔断规则,并通过负载 fortio 测试客户端触发熔断机制进行验证。
vi destinationrule.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 apiVersion: networking.istio.io/v1beta1 kind: DestinationRule metadata: name: productpage spec: host: productpage trafficPolicy: connectionPool: tcp: maxConnections: 1 http: http1MaxPendingRequests: 1 maxRequestsPerConnection: 1 outlierDetection: consecutive5xxErrors: 1 interval: 1s baseEjectionTime: 3m maxEjectionPercent: 100
部署fortio文件进行访问测试
1 2 3 kubectl apply -f samples/httpbin/sample-client/fortio-deploy.yaml kubectl exec fortio-deploy-5bb66f84-rpck8 -c fortio -- /usr/bin/fortio load -qps 0 -n 200 -loglevel Warning http://productpage:9080/
3.部署网关接口实现对外服务【3 分】 通过 istio-1.10.1/samples/bookinfo/networking/bookinfo-gateway.yaml 部署 bookinfo 网关,通过外部浏览器登陆 bookinfo,请将浏览器反馈的结果截图提交答题框.。
1 2 3 4 5 kubectl apply -f istio-1.10.1/samples/bookinfo/networking/bookinfo-gateway.yaml # 将istio-system空间的istio-ingressgateway 的svc中 kubectl edit istio-ingressgateway -n istio-system 改为NodePort
进行访问
1 http://192.168.200.155:30221/productpage