第一套

【任务 1】私有云服务搭建[10分]

【题目 1】基础环境配置[0.5 分]

使用提供的用户名密码,登录提供的 OpenStack 私有云平台,在当前租户下,使用CentOS7.9 镜像,创建两台云主机,云主机类型使用 4vCPU/12G/100G_50G 类型。当前租户下默认存在一张网卡,自行创建第二张网卡并连接至 controller 和 compute 节点(第二张网卡的网段为 10.10.X.0/24,X 为工位号,不需要创建路由)。自行检查安全组策略,以确保网络正常通信与 ssh 连接,然后按以下要求配置服务器:

(1)设置控制节点主机名为 controller,设置计算节点主机名为 compute;

(2)修改 hosts 文件将 IP 地址映射为主机名;

1
2
3
1.查看控制节点名字为 controller 正确计 0.2 分
2.查看 hosts 文件中有正确的主机名和 IP 映射计 0.2 分
3.控制节点正确使用两块网卡计 0.1 分
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
[root@controller ~]# hostname
controller
[root@controller ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.100.10 controller
192.168.100.20 compute
[root@controller ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:3d:4b:e6 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.10/24 brd 192.168.100.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::ee56:e4e:d291:8f31/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: ens34: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:3d:4b:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.200.10/24 brd 192.168.200.255 scope global noprefixroute ens34
valid_lft forever preferred_lft forever
inet6 fe80::fe7c:1bec:9978:2d47/64 scope link noprefixroute
valid_lft forever preferred_lft forever

【题目 2】Yum 源配置[0.5 分]

使用提供的 http 服务地址,在 http 服务下,存在 centos7.9 和 iaas 的网络 yum 源,使用该 http 源作为安装 iaas 平台的网络源。分别设置 controller 节点和 compute 节点的 yum 源文件 http.repo。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
1.查看/etc/yum.repos.d/http.repo 文件,有正确的 baseurl 路径,计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#直接删除默认源
rm -rf /etc/yum.repos.d/*

#创建http类型的yum源
cat > /etc/yum.repos.d/http.repo <<EOF
[centos]
name=centos
baseurl=http://192.168.100.100/centos
gpgcheck=0
enabled=1
[iaas]
name=iaas
baseurl=http://192.168.100.100/iaas/iaas-repo
gpgcheck=0
enabled=1
EOF

#可以通过来验证源的配置是否正确
yum makecache

【题目 3】配置无秘钥 ssh[0.5 分]

配置 controller 节点可以无秘钥访问 compute 节点,配置完成后,尝试 ssh 连接 compute节点的 hostname 进行测试。完成后提交 controller 节点的用户名、密码和 IP 地址到答题框。

1
1.查看控制节点允许计算节点无秘钥登录计 0.5 分
1
2
3
4
5
6
7
8
9
10
[root@controller ~]# ssh root@compute
The authenticity of host 'compute (192.168.100.20)' can't be established.
ECDSA key fingerprint is SHA256:w8T7ol8B+536sySmpugXGrPle6li9IMnc+ijwbcgjLc.
ECDSA key fingerprint is MD5:31:1d:72:34:56:3d:fa:0c:71:30:cf:f4:77:66:b0:b6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'compute' (ECDSA) to the list of known hosts.
Last login: Wed Oct 12 15:13:34 2022
[root@compute ~]# hostname
compute

过程:

1
2
3
4
5
6
7
#创建密钥(回车即可)
ssh-keygen
#上传密钥
ssh-copy-id root@192.168.100.20
#验证
ssh root@compute
hostname

【题目 4】基础安装[0.5 分]

在控制节点和计算节点上分别安装 openstack-iaas 软件包,根据表 2 配置两个节点脚本文件中的基本变量(配置脚本文件为/etc/openstack/openrc.sh)。

image-20221012153852874

1
1.检查环境变量文件配置正确计 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
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
###0.提前准备
#分区
#在 compute 节点上利用空白分区划分 2个 20G 分区作为cinder与swift的存储
#划分1个5G的硬盘做为manila1的存储,见题目11
#划分1个5G的硬盘做为cinder扩展磁盘,见题目12

#安装openstack-iaas
yum install -y openstack-iaas
###2.编辑环境变量,简化脚本
#使用vi底行模式,正则表达式如下
:%s@##.*@@g #删除文件中开头##的所在行
:%s@#@@g #删除文件中开头的#
:g@^$@d #删除文件中所有的空行
:%s/PASS=/PASS=000000/g #快速配置文件中个服务组件的password

#环境变量文件示例
HOST_IP=192.168.100.10 #controller ip address,按照实际环境来
HOST_PASS=000000
HOST_NAME=controller
HOST_IP_NODE=192.168.100.20 #compute ip address,按照实际环境来
HOST_PASS_NODE=000000
HOST_NAME_NODE=compute
network_segment_IP=192.168.100.0/24
RABBIT_USER=openstack
RABBIT_PASS=000000
DB_PASS=000000
DOMAIN_NAME=demo
ADMIN_PASS=000000
DEMO_PASS=000000
KEYSTONE_DBPASS=000000
GLANCE_DBPASS=000000
GLANCE_PASS=000000
PLACEMENT_DBPASS=000000
PLACEMENT_PASS=000000
NOVA_DBPASS=000000
NOVA_PASS=000000
NEUTRON_DBPASS=000000
NEUTRON_PASS=000000
METADATA_SECRET=000000
INTERFACE_NAME=ens34
Physical_NAME=provider
minvlan=1
maxvlan=200
CINDER_DBPASS=000000
CINDER_PASS=000000
BLOCK_DISK=sdb1
SWIFT_PASS=000000
OBJECT_DISK=sdb2
STORAGE_LOCAL_NET_IP=192.168.100.20 #compute IP
TROVE_DBPASS=000000
TROVE_PASS=000000
HEAT_DBPASS=000000
HEAT_PASS=000000
CEILOMETER_DBPASS=000000
CEILOMETER_PASS=000000
AODH_DBPASS=000000
AODH_PASS=000000
ZUN_DBPASS=000000
ZUN_PASS=000000
KURYR_PASS=000000
OCTAVIA_DBPASS=000000
OCTAVIA_PASS=000000
MANILA_DBPASS=000000
MANILA_PASS=000000
SHARE_DISK=sdb3 #manila—Disk
CLOUDKITTY_DBPASS=000000
CLOUDKITTY_PASS=000000
BARBICAN_DBPASS=000000
BARBICAN_PASS=000000

###首先执行初始化包###
(all node)
iaas-pre-host.sh

###3.controller node执行
iaas-install-mysql.sh && iaas-install-keystone.sh && iaas-install-glance.sh \
&& iaas-install-placement.sh && iaas-install-nova-controller.sh \
&& iaas-install-neutron-controller.sh && iaas-install-dashboard.sh \
&& iaas-install-cinder-controller.sh && iaas-install-swift-controller.sh \
&& iaas-install-heat.sh && iaas-install-manila-controller.sh \
&& iaas-install-cloudkitty.sh && iaas-install-barbican.sh

###4.compute node 执行
#提示:当控制节点在部署脚本的时候,计算节点也别闲着,可以为其安装相应的包
cat /usr/local/bin/iaas-*compute.sh | grep yum

#然后将如上罗列出来的内容全部安装后,等待controller节点的脚本执行后,执行如下内容
iaas-install-nova-compute.sh && iaas-install-neutron-compute.sh \
&& iaas-install-cinder-compute.sh && iaas-install-swift-compute.sh \
&& iaas-install-manila-compute.sh

【题目 5】数据库安装与调优[0.5 分]

在 controller 节点上使用 iaas-install-mysql.sh 脚本安装 Mariadb、Memcached、RabbitMQ

等服务。安装服务完毕后,修改/etc/my.cnf 文件,完成下列要求:

1.设置数据库支持大小写;

2.设置数据库缓存 innodb 表的索引,数据,插入数据时的缓冲为 4G;

3.设置数据库的 log buffer 为 64MB;

4.设置数据库的 redo log 大小为 256MB;

1
1.检查数据库配置正确计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@controller ~]# mysql -uroot -p000000 -e " show variables like 'innodb_log%';"
+-----------------------------+-----------+
| Variable_name | Value |
+-----------------------------+-----------+
| innodb_log_buffer_size | 67108864 |
| innodb_log_checksums | ON |
| innodb_log_compressed_pages | ON |
| innodb_log_file_size | 268435456 |
| innodb_log_files_in_group | 2 |
| innodb_log_group_home_dir | ./ |
| innodb_log_optimize_ddl | ON |
| innodb_log_write_ahead_size | 8192 |
+-----------------------------+-----------+

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vi /etc/my.cnf
#大小写敏感
lower_case_table_names = 1
#缓存区
innodb_buffer_pool_size = 4G
#设置数据库的 log buffer
innodb_log_buffer_size = 64M
#InnoDB redo log大小
innodb_log_file_size = 256M
#设置数据库的 redo log 文件组为 2
innodb_log_files_in_group = 2

#重启服务
systemctl restart mariadb

【题目 6】Keystone 服务安装与使用[0.5 分]

在 controller 节点上使用 iaas-install-keystone.sh 脚本安装 Keystone 服务。安装完成后,使用相关命令,创建用户 chinaskill,密码为 000000。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查 keystone 服务安装正确计 0.2 分
2.检查 chinaskill 用户创建正确计 0.3 分
1
2
3
4
5
6
7
8
9
10
11
[root@controller ~]# openstack user show chinaskill
+---------------------+----------------------------------+
| Field | Value |
+---------------------+----------------------------------+
| domain_id | default |
| enabled | True |
| id | f79373ccd5d34b34a023f18c5f181826 |
| name | chinaskill |
| options | {} |
| password_expires_at | None |
+---------------------+----------------------------------+

过程

1
2
3
4
5
source /etc/keystone/admin-openrc.sh
#创建用户
openstack user create chinaskill --password 000000
#查看是否创建成功
openstack user show chinaskill

【题目 7】Glance 安装与使用[0.5 分]

在 controller 节点上使用 iaas-install-glance.sh 脚本安装 glance 服务。使用命令将提供的 cirros-0.3.4-x86_64-disk.img 镜像(该镜像在 HTTP 服务中,可自行下载)上传至平台,命名为 cirros,并设置最小启动需要的硬盘为 10G,最小启动需要的内存为 1G。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查 glance 服务安装正确计 0.1 分
2.检查 cirros 镜像最小启动硬盘与内存配置正确计 0.4 分
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
[root@controller ~]# openstack image show cirros
+------------------+------------------------------------------------------------------------ -------------------------------------------------------------------------------------------- ------------------------+
| Field | Value |
+------------------+------------------------------------------------------------------------ -------------------------------------------------------------------------------------------- ------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | 2022-10-12T08:42:35Z |
| disk_format | qcow2 |
| file | /v2/images/b757b50b-fd2c-4a42-9bff-31dcf0585917/file |
| id | b757b50b-fd2c-4a42-9bff-31dcf0585917 |
| min_disk | 10 |
| min_ram | 1024 |
| name | cirros |
| owner | ef3705db528144cc9a33f8ace06d6d3b |
| properties | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949 f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bb db2', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2022-10-12T08:43:47Z |
| virtual_size | None |
| visibility | shared |
+------------------+------------------------------------------------------------------------ -------------------------------------------------------------------------------------------- ------------------------+

过程:

1
2
3
4
#创建镜像
openstack image create cirros --disk-format qcow2 --container bare --file /root/cirros-0.3.4-x86_64-disk.img
#设置镜像最小启动需要的硬盘为 10G,最小启动需要的内存为 1G
openstack image set cirros --min-disk 10 --min-ram 1024

【题目 8】Nova 安装与优化[0.5 分]

在 controller 节点和 compute 节点上分别使用 iaas-install-placement.sh 脚本、iaas-install-nova -controller.sh 脚本、iaas-install-nova-compute.sh 脚本安装 Nova 服务。安装完成后,请修改 nova 相关配置文件,解决因等待时间过长而导致虚拟机启动超时从而获取不到 IP 地址而报错失败的问题。配置完成后提交 controller 点的用户名、密码和 IP 地址到答题框。

1
1.检查 nova 服务解决超时问题配置正确计 0.5 分
1
2
cat /etc/nova/nova.conf |grep vif_plugging_is_fatal
vif_plugging_is_fatal=false

过程:

1
2
3
4
5
vi /etc/nova/nova.conf 
vif_plugging_is_fatal=false

#重启nova服务
systemctl restart openstack-nova*

【题目 9】Neutron 安装[0.5 分]

使用提供的脚本 iaas-install-neutron-controller.sh 和 iaas-install-neutron-compute.sh,在controller 和 compute 节点上安装neutron 服务。完成后提交控制节点的用户名、密码和 IP地址到答题框。

1
2
1.检查 neutron 服务安装正确计 0.2 分
2.检查 neutron 服务的 linuxbridge 网桥服务启动正确计 0.3 分
1
2
[root@controller ~]# openstack-service status | grep linuxbridge
MainPID=17877 Id=neutron-linuxbridge-agent.service ActiveState=active

【题目 10】Doshboard 安装[0.5 分]

在controller节点上使用iaas-install-dashboad.sh脚本安装dashboad服务。安装完成后,将 Dashboard 中的 Djingo 数据修改为存储在文件中(此种修改解决了 ALL-in-one 快照在其他云平台 Dashboard 不能访问的问题)。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查 Dashboard 服务安装正确计 0.2 分
2.检查 Dashboard 服务中 Djingo 数据修改为存储在文件中配置正确计 0.3 分
1
2
cat /etc/openstack-dashboard/local_settings |grep django
SESSION_ENGINE = 'django.contrib.sessions.backends.file'

过程:

1
2
3
4
vi /etc/openstack-dashboard/local_settings
SESSION_ENGINE = 'django.contrib.sessions.backends.file'
#重启服务生效配置
systemctl restart httpd

【题目 11】Swift 安装[0.5 分]

在 控 制 节 点 和 计 算 节 点 上 分 别 使 用 iaas-install-swift-controller.sh 和iaas-install-swift-compute.sh 脚本安装 Swift 服务。安装完成后,使用命令创建一个名叫examcontainer 的容器,将 cirros-0.3.4-x86_64-disk.img 镜像上传到 examcontainer 容器中,并设置分段存放,每一段大小为 10M。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查 swift 服务安装正确计 0.3 分
2.分段上传 cirros 镜像正确计 0.2 分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@controller ~]# swift stat examcontainer  cirros-0.3.4-x86_64-disk.img
Account: AUTH_ef3705db528144cc9a33f8ace06d6d3b
Container: examcontainer
Object: cirros-0.3.4-x86_64-disk.img
Content Type: application/octet-stream
Content Length: 13287936
Last Modified: Wed, 12 Oct 2022 09:32:27 GMT
ETag: "5cde37512919eda28a822e472bb0a2dd"
Manifest: examcontainer_segments/cirros-0.3.4-x86_64-disk.img/1665563891.781025/13287936/10485760/
Meta Mtime: 1665563891.781025
Accept-Ranges: bytes
X-Timestamp: 1665567146.81794
X-Trans-Id: tx47b60b986ef545d19e59d-00634689e7
X-Openstack-Request-Id: tx47b60b986ef545d19e59d-00634689e7

过程

1
2
3
4
5
6
#创建examcontainer容器
swift post examcontainer
#将镜像分段上传
swift upload examcontainer -S 10485760 cirros-0.3.4-x86_64-disk.img
#查看是否成功上传
swift stat examcontainer cirros-0.3.4-x86_64-disk.img

【题目 12】Cinder 创建硬盘[0.5 分]

在 控 制 节 点 和 计 算 节 点 分 别 使 用

iaas-install-cinder-controller.sh 、iaas-install-cinder-compute.sh 脚本安装 Cinder 服务,请在计算节点,对块存储进行扩容操作,即在计算节点再分出一个 5G 的分区,加入到 cinder 块存储的后端存储中去。完成后提交计算节点的用户名、密码和 IP 地址到答题框。

1
1.检查 cinder 后端存储扩容成功计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
vgdisplay
--- Volume group ---
VG Name cinder-volumes
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 49.99 GiB
PE Size 4.00 MiB
Total PE 12798
Alloc PE / Size 9748 / <38.08 GiB
Free PE / Size 3050 / 11.91 GiB
VG UUID DgfDCG-y8uU-Slr0-V9J5-jw1H-nrsT-SokTeh

过程:

1
2
3
4
#创建物理卷
pvcreate /dev/sdc2
#扩展
vgextend cinder-volumes /dev/sdc2

【题目 13】Manila 服务安装与使用[0.5 分]

在 控 制 和 计 算 节 点 上 分 别 使 用

iaas-install-manila-controller.sh 和iaas-install-manila-compute.sh 脚本安装 manila 服务。安装服务后创建 default_share_type 共享类型(不使用驱动程序支持),接着创建一个大小为 2G 的共享存储名为 share01 并开放share01 目录对 OpenStack 管理网段使用权限。最后提交控制节点的用户名、密码和 IP 地址到答题框。

1
1.检查 share01 共享存储正确创建并赋予权限计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@controller ~]# manila type-list
+--------------------------------------+--------------------+------------+----------- -+--------------------------------------+----------------------+-------------+
| ID | Name | visibility | is_default | required_extra_specs | optional_extra_specs | Description |
+--------------------------------------+--------------------+------------+----------- -+--------------------------------------+----------------------+-------------+
| 11caa227-7ae2-40cf-bdd1-54ca6712dc5e | default_share_type | public | YES | driver_handles_share_servers : False | | None |
+--------------------------------------+--------------------+------------+----------- -+--------------------------------------+----------------------+-------------+
[root@controller ~]# manila list
+--------------------------------------+---------+------+-------------+-----------+-- ---------+--------------------+-----------------------------+-------------------+
| ID | Name | Size | Share Proto | Status | I s Public | Share Type Name | Host | Availability Zone |
+--------------------------------------+---------+------+-------------+-----------+-- ---------+--------------------+-----------------------------+-------------------+
| b8e66c11-64e3-48f3-aed0-ca474aa57537 | share01 | 2 | NFS | available | F alse | default_share_type | compute@lvm#lvm-single-pool | nova |
+--------------------------------------+---------+------+-------------+-----------+-- ---------+--------------------+-----------------------------+-------------------+

过程:

1
2
3
4
5
#创建共享类型(不使用驱动程序支持)
manila type-create default_share_type False
#创建一个大小为 2G 的共享存储名为 share01 并开放share01 目录对 OpenStack 管理网段使用权限
manila create NFS 2 --name share01
manila access-allow share01 ip 192.168.100.0/24 --access-level rw

【题目 14】Barbican 服务安装与使用[0.5 分]

使用 iaas-install-barbican.sh 脚本安装 barbican 服务,安装服务完毕后,使用 openstack命令创建一个名为 secret01 的密钥,创建完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
1.检查 secret01 密钥创建正确计 0.5 分
1
2
3
4
5
6
7
[root@controller ~]# openstack secret list
+------------------------------------------------------------------------+----------+---------------------------+--------+-----------------------------+-----------+------------+-------------+------+------------+
| Secret href | Name | Created | Status | Content types | Algorithm | Bit length | Secret type | Mode | Expiration |
+------------------------------------------------------------------------+----------+---------------------------+--------+-----------------------------+-----------+------------+-------------+------+------------+
| http://controller:9311/v1/secrets/3ffdbd31-b33e-4298-b8c8-104601cd4a72 | secret01 | 2022-10-13T01:45:56+00:00 | ACTIVE | {u'default': u'text/plain'} | aes | 256 | opaque | cbc | None |
+------------------------------------------------------------------------+----------+---------------------------+--------+-----------------------------+-----------+------------+-------------+------+------------+

过程

1
openstack secret store --name secret01 --payload secretkey

【题目 15】Cloudkitty 服务安装与使用[1 分]

使用 iaas-install-cloudkitty.sh 脚本安装 cloudkitty 服务,安装完毕后,启用 hashmap 评级模块,接着创建 volume_thresholds 组,创建服务匹配规则 volume.size,并设置每 GB 的价格为 0.01。接下来对应大量数据设置应用折扣,在组 volume_thresholds 中创建阈值,设置若超过 50GB 的阈值,应用 2%的折扣(0.98)。设置完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查 hashmap 评级模块启用成功计 0.2 分
2.检查服务匹配规则 volume.size 创建成功 0.8 分
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@controller ~]# cloudkitty hashmap service list
+-------------+--------------------------------------+
| Name | Service ID |
+-------------+--------------------------------------+
| volume.size | 8e4db95b-45ae-44fd-87d5-424b0aac9614 |
+-------------+--------------------------------------+
[root@controller ~]# openstack rating module enable hashmap
+---------+---------+----------+
| Module | Enabled | Priority |
+---------+---------+----------+
| hashmap | True | 1 |
+---------+---------+----------+

过程:

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
#启动评级模块
openstack rating module enable hashmap
#创建组
cloudkitty hashmap group create volume_thresholds
+-------------------+--------------------------------------+
| Name | Group ID |
+-------------------+--------------------------------------+
| volume_thresholds | cac489fd-58b8-4de8-a4d3-08a0db1aa3d8 |
+-------------------+--------------------------------------+
#创建服务
cloudkitty hashmap service create volume.size
+-------------+--------------------------------------+
| Name | Service ID |
+-------------+--------------------------------------+
| volume.size | 8e4db95b-45ae-44fd-87d5-424b0aac9614 |
+-------------+--------------------------------------+
#创建匹配规则
cloudkitty hashmap mapping create -s 8e4db95b-45ae-44fd-87d5-424b0aac9614 -t flat -g cac489fd-58b8-4de8-a4d3-08a0db1aa3d8 0.01
+--------------------------------------+-------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
| Mapping ID | Value | Cost | Type | Field ID | Service ID | Group ID | Project ID |
+--------------------------------------+-------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
| 65f9489f-035e-4bf7-8cf6-664fde0ca446 | None | 0.01000000 | flat | None | 8e4db95b-45ae-44fd-87d5-424b0aac9614 | cac489fd-58b8-4de8-a4d3-08a0db1aa3d8 | None |
+--------------------------------------+-------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
#创建阈值
cloudkitty hashmap threshold create -s8e4db95b-45ae-44fd-87d5-424b0aac9614 -g cac489fd-58b8-4de8-a4d3-08a0db1aa3d8 -t rate 50 0.98
+--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
| Threshold ID | Level | Cost | Type | Field ID | Service ID | Group ID | Project ID |
+--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+
| 3f5a8dfe-2ed8-4e1b-b617-a5bc7ef8a187 | 50.00000000 | 0.98000000 | rate | None | 8e4db95b-45ae-44fd-87d5-424b0aac9614 | cac489fd-58b8-4de8-a4d3-08a0db1aa3d8 | None |
+--------------------------------------+-------------+------------+------+----------+--------------------------------------+--------------------------------------+------------+

【题目 16】OpenStack 平台内存优化[0.5 分]

搭建完 OpenStack 平台后,关闭系统的内存共享,打开透明大页。完成后提交控制节点的用户名、密码和 IP 地址到答题框。

1
1.检查系统内存优化成功计 0.5 分
1
2
cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

过程

1
2
3
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
cat /sys/kernel/mm/transparent_hugepage/defrag
always madvise [never]

【题目 17】修改文件句柄数[0.5 分]

Linux 服务器大并发时,往往需要预先调优 Linux 参数。默认情况下,Linux 最大文件句柄数为 1024 个。当你的服务器在大并发达到极限时,就会报出“too many open files”。创建一台云主机,修改相关配置,将控制节点的最大文件句柄数永久修改为 65535。配置完成后提交 controller 点的用户名、密码和 IP 地址到答题框。

1
1.检查配置 linux 系统句柄数为 65535 成功计 0.5 分
1
2
3
4
5
6
7
8
9
#临时生效
ulimit -n 65535
#永久生效
vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535

#查看
ulimit -n

【题目 18】Linux 系统调优-防止 SYN 攻击[1 分]

修改 controller 节点的相关配置文件,开启 SYN cookie,防止 SYN 洪水攻击。完成后提交 controller 节点的用户名、密码和 IP 地址到答题框。

1
1.检查开启 SYN cookie 配置计 1 分
1
2
3
4
5
6
vi /etc/sysctl.conf
net.ipv4.tcp_max_syn_backlog=2048
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_syn_retries = 0
#配置生效
sysctl -p

**【任务 **2】私有云服务运维[10分]

【题目 1】OpenStack 开放镜像权限[0.5 分]

使 用 OpenStack 私 有 云 平 台 , 在 OpenStack 平台的 admin 项 目 中 使 用cirros-0.3.4-x86_64-disk.img 镜像文件创建名为 glance-cirros 的镜像,通过 OpenStack 命令将glance-cirros 镜像指定 demo 项目进行共享使用。配置完成后提交 controller 点的用户名、密码和 IP 地址到答题框。

1
1.检查 glance-cirros 镜像权限开放正确计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
[root@controller ~]# openstack image add project glance-cirros demo
+------------+--------------------------------------+
| Field | Value |
+------------+--------------------------------------+
| created_at | 2022-10-13T03:55:11Z |
| image_id | 5e98f80e-34a0-40f7-981a-ef35bb3d673c |
| member_id | cc5b38915a0343368e9e7b7560eeb6ca |
| schema | /v2/schemas/member |
| status | pending |
| updated_at | 2022-10-13T03:55:11Z |
+------------+--------------------------------------+

过程:

1
2
3
4
#上传镜像
openstack image create glance-cirros --disk-format qcow2 --container bare --file cirros-0.3.4-x86_64-disk.img --project admin
#对demo项目进行共享使用
openstack image add project glance-cirros demo

【题目 2】OpenStack 消息队列调优[0.5 分]

OpenStack 各服务内部通信都是通过 RPC 来交互,各 agent 都需要去连接 RabbitMQ;随着各服务 agent 增多,MQ 的连接数会随之增多,最终可能会到达上限,成为瓶颈。使用自行搭建的OpenStack私有云平台,分别通过用户级别、系统级别、配置文件来设置RabbitMQ服务的最大连接数为 10240,配置完成后提交修改节点的用户名、密码和 IP 地址到答题框。

1
1.检查 rabbitmq 服务最大连接数正确计 0.5 分
1
2
3
4
5
vi /etc/sysconfig/memcached
MAXCONN="10240"

#重启服务
systemctl restart mecached

【题目 3】OpenStack Glance 镜像压缩[0.5 分]

使用自行搭建的 OpenStack 平台。在 HTTP 服务中存在一个镜像为CentOS7.5-compress.qcow2 的镜像,请使用 qemu 相关命令,对该镜像进行压缩,压缩后的镜像命名为 chinaskill-js-compress.qcow2 并存放在/root 目录下。完成后提交 controller 点的用户名、密码和 IP 地址到答题框。

1
1.检查镜像压缩正确计 0.5 分
1
qemu-img  convert -c -O qcow2 CentOS7.5-compress.qcow2 /root/chinaskill-js-compress.qcow2

【题目 4】glance 对接 cinder 后端存储[0.5 分]

在自行搭建的 OpenStack平台中修改相关参数,使 glance 可以使用 cinder作为后端存储,将镜像存储于 cinder 卷中。使用 cirros-0.3.4-x86_64-disk.img 文件创建 cirros-image 镜像存储于 cirros-cinder 卷中,通过 cirros-image 镜像使用 cinder 卷启动盘的方式进行创建虚拟机。完成后提交修改节点的用户名、密码和 IP 地址到答题框。

1
1.检查修改 glance 后端存储为 cinder 正确计 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
[root@controller ~]# vi /etc/glance/glance-api.conf

#show_multiple_locations = false

改为
show_multiple_locations = true


[root@controller ~]# systemctl restart openstack-glance-*
[root@controller ~]# vi /etc/cinder/cinder.conf

#allowed_direct_url_schemes =
改为
allowed_direct_url_schemes =cinder

#image_upload_use_internal_tenant = false
改为
image_upload_use_internal_tenant = true
#最后重启cinder
[root@controller ~]# systemctl restart openstack-cinderack-cinder-scheduler.service httpd

代码不全,还差一些操作,只有一半的分

【题目 5】OpenStack Heat 运维:创建容器[0.5 分]

在自行搭建的 OpenStack 私 有 云 平 台 上 , 在 /root 目录下编写 Heat 模 板create_container.yaml,要求执行 yaml 文件可以创建名为 heat-swift 的容器。完成后提交控制节点的用户名、密码和 IP 地址到答题框。(在提交信息前请准备好 yaml 模板执行的环境)

1
1.执行 heat 模板文件成功创建容器计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
12
cat create_container.yaml

heat_template_version: 2018-08-31
description: create container
resources:
user:
type: OS::Swift::Container
properties:
name: heat-swift

#运行模板测试
heat stack-create -f create_container.yaml heat-swift

【题目 6】OpenStack Nova 清除缓存[0.5 分]

在 OpenStack 平台的一台计算节点创建虚拟机,若是第一次在该节点创建次虚拟机,会先将镜像文件复制到该计算节点录/var/lib/nova/instances/_base。长期下来,该目录会占用比较大的磁盘空间而要清理。可以通过修改 nova 的配置文件来自动清理该缓存目录,即在该节点没有使用某镜像启动的云主机,那么这个镜像在过一定的时间后会被自动删除。配置完成后提交改动节点的用户名、密码和 IP 地址到答题框。

1
1.检查 nova 配置自动清理缓存文件正确计 0.5 分
1
2
3
4
5
6
vi /etc/nova/nova.conf
[DEFAULT]]
remove_unused_base_images=true
image_cache_manager_interval=2400
remove_unused_original_minimum_age_seconds=86400

【题目 7】Redis 一主二从三哨兵模式[1 分]

使用提供的 OpenStack 私有云平台,申请三台 CentOS7.9 系统的云主机,使用提供的http 源,在三个节点自行安装 Redis 服务并启动,配置 Redis 的访问需要密码,密码设置为123456。然后将这三个 Redis 节点配置为 Redis 的一主二从三哨兵架构,即一个 Redis 主节点,两个从节点,三个节点均为哨兵节点。配置完成后提交 Redis 主节点的用户名、密码和IP 地址到答题框。

1
2
1.检查 redis 主从集群部署正确计 0.5 分
2.检查 redis 集群部署为哨兵节点正确计 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
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
#安装redis
yum install -y redis
#修改配置文件/etc/redis.conf
1.先在网络部分注释掉单机连接那一行,即注释掉bind 127.0.0.1
2.同样我们要将后台运行打开:daemonize no,设置为yes
3.将 保护模式关闭:protected-mode yes 改为:protected-mode no

4.打开RDB持久化配置:
#RDB持久化策略 默认三种方式,[900秒内有1次修改],
#[300秒内有10次修改],[60秒内有10000次修改]即触发RDB持久化,
#我们可以手动修改该参数或新增策略
save 900 1
save 300 10
save 60 10000
#RDB文件名
dbfilename dump.rdb
#RDB文件存储路径
dir ./
策略配置:
#在seconds秒内有changes次数据修改就触发RDB持久化

5.开启AOF持久化配置
appendonly yes
#AOF文件名
appendfilename "appendonly.aof"
#AOF文件存储路径 与RDB是同一个参数,共用一个文件路径
dir ./ #即bin目录下
#AOF策略,一般都是选择第一种[always:每个命令都记录],
#[everysec:每秒记录一次],[no:看机器的心情高兴了就记录,linux一般半个小时同步一次]
#appendfsync always
appendfsync everysec
# appendfsync no
#aof文件大小比起上次重写时的大小,增长100%(配置可以大于100%)时,触发重写。
#[假如上次重写后大小为10MB,当AOF文件达到20MB时也会再次触发重写,以此类推
auto-aof-rewrite-percentage 100
#aof文件大小超过64MB*2时,触发重写,
#为何要乘以2,因为auto-aof-rewrite-percentage 100 是翻倍即100%,
#达到翻倍时才重写
auto-aof-rewrite-min-size 64mb
6.打开混合持久化:
#6.aof-use-rdb-preamble yes # 检查混合持久化是否打开,redis5.0后默认开启

#将修改后的配置文件传到其他节点
scp /etc/redis.conf root@slave1:/etc/redis.conf
scp /etc/redis.conf root@slave2:/etc/redis.conf

#启动redis将slave各节点配置成从机
systemctl start redis
#配置slave1
redis-cli -p 6379
> slaveof 192.168.200.101 6379
> info replication
#配置slave2
redis-cli -p 6379
> slaveof 192.168.200.101 6379
> info replication

#主节点查看配置是否成功
redis-cli -p 6379
>info replication

配置三哨兵

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
#解压压缩包
tar -zxvf redis-5.0.7.tar.gz -C /opt
#修改配置文件
vim /opt/redis-5.0.7/sentinel.conf
protected-mode no #17行,关闭保护模式
port 26379 #21行,Redis哨兵默认的监听端口
daemonize yes #26行,指定sentinel为后台启动
logfile "/var/log/sentinel.log" #36行,指定日志存放路径
dir "/var/lib/redis/6379" #65行,指定数据库存放路径(没有这个文件夹需要手动创建)
sentinel monitor mymaster 192.168.154.19 6379 2 #84行,修改 指定该哨兵节点监控192.168.184.10:6379这个主节点,该主节点的名称是mymaster,最后的2的含义与主节点的故障判定有关:至少需要2个哨兵节点同意,才能判定主节点故障并进行故障转移
sentinel down-after-milliseconds mymaster 30000 #113行,判定服务器down掉的时间周期,默认30000毫秒(30秒)
sentinel failover-timeout mymaster 180000 #146行,故障节点的最大超时时间为180000(180秒)


#启动哨兵
cd /opt/redis-5.0.7/
redis-sentinel sentinel.conf &
#注意!先启动主服务器,再启动从服务器
#查看信息
redis-cli -p 26379 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=192.168.58.30:6379,slaves=2,sentinels=3
[1]+ 完成 redis-sentinel sentinel.conf

【题目 8】Redis 服务调优-AOF[1 分]

使用上一题安装的 Redis 服务。在 Redis 中,AOF 配置为以三种不同的方式在磁盘上执行 write 或者 fsync。假设当前 Redis 压力过大,请配置 Redis 不执行 fsync。除此之外,避免AOF 文件过大,Redis 会进行 AOF 重写,生成缩小的 AOF 文件。请修改配置,让 AOF 重写时,不进行 fsync 操作。配置完成后提交 Redis 节点的用户名、密码和 IP 地址到答题框。

1
2
1.检查配置 redis 不执行 fsync 正确计 0.5 分、
2.检查配置 redis 进行 AOF 重写不执行 fsync 正确计 0.5 分
1
2
3
4
5
6
7
8
9
10
11
[root@master ~]# vim /etc/redis.conf

no-appendfsync-on-rewrite no
aof-rewrite-incremental-fsync yes

#连个参数分别改为

aof-rewrite-incremental-fsync no
no-appendfsync-on-rewrite yes
#配置就是设置为yes时候,在aof重写期间会停止aof的fsync操作
[root@master ~]# systemctl restart redis

【题目 9】应用部署:堡垒机部署[0.5 分]

使用提供的 OpenStack 平台申请一台 CentOS7.9 的云主机,使用提供的软件包安装JumpServer 堡垒机服务,并配置使用该堡垒机对接自己安装的 controller 和 compute 节点。完成后提交 JumpServer 节点的用户名、密码和 IP 地址到答题框。

1
1.检查堡垒机部署正确计 0.5 分

【题目 10】skywalking 服务部署与应用[1 分]

使用提供的 OpenStack 私有云平台,申请一台 centos7.9 系统的云主机,使用提供的软件包安装 Elasticsearch 服务和 skywalking 服务,将 skywalking 的 UI 访问端口修改为 8888。接下来再申请一台CentOS7.9 的云主机,用于搭建gpmall 商城应用,并配置SkyWalking Agent, 将 gpmall 的 jar 包放置探针并启动。安装与配置完成后提交 skywalking 节点的用户名、密码和 IP 地址到答题框。登录物理OpenStack平台,使用CentOS7.9镜像创建两台云主机(node-1,mall),云主机类型使用4VCPU/8GB内存/100GB硬盘。创建后的云主机作为本次案例的实验节点。

1
1.检查 skywalking 服务部署正确计 1 分

【题目 11】Linux 内核优化[1 分]

在使用 Linux 服务器的时候,TCP 协议规定,对于已经建立的连接,网络双方要进行四次挥手才能成功断开连接,如果缺少了其中某个步骤,将会使连接处于假死状态,连接本身占用的资源不会被释放。因为服务器程序要同时管理大量连接,所以很有必要保证无用的连接完全断开,否则大量僵死的连接会浪费许多服务器资源。创建一台 CentOS7.9 云主机,修改相应的配置文件,分别开启 SYN Cookies;允许将 TIME-WAIT sockets 重新用于新的 TCP 连接;开启TCP 连接中TIME-WAIT sockets 的快速回收;修改系統默认的 TIMEOUT 时间为 30。完成后提交修改节点的用户名、密码和 IP 地址到答题框。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vim /etc/sysctl.conf

#添加如下参数
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

sysctl -p
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

【任务 3】私有云运维开发[10 分]

【题目 1】Ansible 服务部署:部署 MariaDB 集群[2 分]

使用OpenStack 私有云平台,创建 4 台系统为centos7.9 的云主机,其中一台作为 Ansible 的母机并命名为 ansible,另外三台云主机命名为 node1、node2、node3;使用这一台母机, 编写 Ansible 脚本(在/root 目录下创建 example 目录作为 Ansible 工作目录,部署的入口文件命名为 cscc_install.yaml ) , 对其他三台云主机进行安装高可用数据库集群
(MariaDB_Galera_cluster,数据库密码设置为 123456)的操作(所需的安装包在 HTTP 服务中)。完成后提交 Ansible 节点的用户名、密码和 IP 地址到答题框。(考试系统会连接到你的Ansible 节点,去执行 Ansible 脚本,请准备好 Ansible 运行环境,以便考试系统访问)

(1)环境准备

①ansible部署

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#1.创建工作目录
mkdir example
cd example

vi ansible.cfg
[defaults]
inventory = /root/example/inventory ###声明主机组
remote_user = root

#创建主机组
vi inventory ###设置主机组,便于后面“when模块”进行筛选使用
[node1]
node1
[node2]
node2
[node3]
node3

#将公钥进行上传

#2.创建roles目录,编写playbook
mkdir roles
cd roles/
#生成role
ansible-galaxy init mariadb-galera-cluster
cd mariadb-galera-cluster

#编写file
cd files
#vi mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

#vi server1.cnf(需要创建三个server1,server2,server3,把"wsrep_node_name=",“wsrep_node_address=”替换即可)
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
user=mysql

default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=128M

binlog_format=ROW
log-error=/var/log/mysqld.log

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so

wsrep_node_name='galera1'
wsrep_node_address="192.168.93.11"
wsrep_cluster_name='galera-cluster'
wsrep_cluster_address="gcomm://192.168.93.11,192.168.93.12,192.168.93.13"

wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_slave_threads=4
wsrep_sst_method=rsync

cd tasks
#编写yum.yml
vi yum.yml
- name: mv yum#若联网无需删除,但需修改repo添加repo
shell: 'mv /etc/yum.repos.d/* /etc/yum'
- name: copy mariadb-repo
copy: src=mariadb.repo dest=/etc/yum.repos.d/mariadb.repo
- name: change repo
shell: sed -i 's#yum\.mariadb\.org#mirrors.ustc.edu.cn/mariadb/yum#' /etc/yum.repos.d/mariadb.repo
- name: install mariadb.galera.mysql-python
shell: 'yum install -y MariaDB-server MariaDB-client rsync'

#编写service.yml
- name: start node1 mariadb
service: name=mariadb state=started enabled=yes

- name: set node1 mysql_user
shell: mysqladmin -uroot password 123456

- name: copy node1 config
copy: src=roles/mariadb-galera-cluster/files/server1.cnf dest=/etc/my.cnf.d/server.cnf
when: "'node1' in group_names"

- name: copy node2 config
copy: src=roles/mariadb-galera-cluster/files/server2.cnf dest=/etc/my.cnf.d/server.cnf
when: "'node2' in group_names"

- name: copy node3 config
copy: src=roles/mariadb-galera-cluster/files/server3.cnf dest=/etc/my.cnf.d/server.cnf
when: "'node3' in group_names"

- name: stop node1 mariadb
service: name=mariadb state=stopped
when: "'node1' in group_names"

- name: start node1 galera
shell: galera_new_cluster
when: "'node1' in group_names"

- name: restart node2 mariadb
service: name=mariadb state=restarted
when: "'node2' in group_names"

- name: restart node3 mariadb
service: name=mariadb state=restarted
when: "'node3' in group_names"
#########这里面有个mysql_user模块,通过“ansible-doc -s mysql_user”来查看这个模块的不详细信息

#编写 main.yml
vi main.yml
- include: install.yml
- include: service.yml

#编写入口文件
vi cscc_install.yaml
- hosts: all
remote_user: root
roles:
- mariadb-galera-cluster

#文件在文档test

②手动部署

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
https://blog.csdn.net/networken/article/details/106297814#关闭防火墙
systemctl disable --now firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config && setenforce 0
#修改主机名
hostnamectl set-hostname xxx
#修改主机名解析
cat >> /etc/hosts <<EOF
192.168.93.11 galera1
192.168.93.12 galera2
192.168.93.13 galera3
EOF
#配置yum源
cat > /etc/yum.repos.d/mariadb.repo <<EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
#替换为中科大源
sed -i 's#yum\.mariadb\.org#mirrors.ustc.edu.cn/mariadb/yum#' /etc/yum.repos.d/mariadb.repo
#安装mariadb、galera和rsync,其中galera作为依赖自动安装
yum install -y MariaDB-server MariaDB-client rsync

#配置节点1
cat > /etc/my.cnf.d/server.cnf <<EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
user=mysql

default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=128M

binlog_format=ROW
log-error=/var/log/mysqld.log

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so

wsrep_node_name='galera1'
wsrep_node_address="192.168.93.11"
wsrep_cluster_name='galera-cluster'
wsrep_cluster_address="gcomm://192.168.93.11,192.168.93.12,192.168.93.13"

wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_slave_threads=4
wsrep_sst_method=rsync
EOF

#配置节点二
cat > /etc/my.cnf.d/server.cnf <<EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
user=mysql

default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=128M

binlog_format=ROW
log-error=/var/log/mysqld.log

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so

wsrep_node_name='galera2'
wsrep_node_address="192.168.93.12"
wsrep_cluster_name='galera-cluster'
wsrep_cluster_address="gcomm://192.168.93.11,192.168.93.12,192.168.93.13"

wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_slave_threads=4
wsrep_sst_method=rsync
EOF
#配置节点三:
cat > /etc/my.cnf.d/server.cnf <<EOF
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
user=mysql

default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=128M

binlog_format=ROW
log-error=/var/log/mysqld.log

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so

wsrep_node_name='galera3'
wsrep_node_address="192.168.93.13"
wsrep_cluster_name='galera-cluster'
wsrep_cluster_address="gcomm://192.168.93.11,192.168.93.12,192.168.93.13"

wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_slave_threads=4
wsrep_sst_method=rsync
EOF


#启动集群
galera_new_cluster
systemctl enable mariadb

#另外两个
systemctl enable --now mariadb
验证集群状态,默认未配置密码直接回车:
[root@galera1 ~]# mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
Enter password:
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 3 |
+--------------------+-------+