cephopenstack集成创建交互密钥及同步修改kolla-ansible配置脚本

create-keys-file.sh

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
#!/bin/bash
#kolla-ansible合并配置文件特性脚本实现
#set -e
yellow="33m"
green="34m"
keys_dir="/etc/ceph" # 部署节点ceph目录
ceph_file=`ls /etc/ceph`
deploy_host="localhost" # 部署节点
echo "${0}脚本将创建kolla-ansible文件合并所需配置 详情参考:https://gegewu-cloud.github.io/2023/06/02/ceph与openstack-yoga集成/"
rbd_secret_uuid=`cat /etc/kolla/passwords.yml | grep rbd_secret_uuid |awk 'NR==2{print $2}'`
create_keys() {
ls ${keys_dir} |grep "ceph.client.cinder.keyring"
if [ $? = 0 ];
then
echo -e "\033[${green} ####################openstack与ceph交互密钥已创建######################### \033[0m"
else
echo -e "\033[${yellow} 开始执行openstack与ceph创建交互密钥 \033[0m"
cd ${keys_dir} && ceph auth get-or-create client.cinder mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=volumes, allow rwx pool=vms, allow rx pool=images' -o ceph.client.cinder.keyring
cd ${keys_dir} && ceph auth get-or-create client.glance mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=images' -o ceph.client.glance.keyring
cd ${keys_dir} && ceph auth get-or-create client.cinder-backup mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=backups, allow rwx pool=volumes' -o ceph.client.cinder-backup.keyring
cd ${keys_dir} && ceph auth get-or-create client.nova mon 'allow r' osd 'allow class-read object_prefix rbd_children, allow rwx pool=vms, allow rwx pool=volumes, allow rx pool=images' -o ceph.client.nova.keyring

echo -e "\033[36m openstack与ceph交互密钥
ceph.client.cinder.keyring
ceph.client.glance.keyring
ceph.client.cinder-backup.keyring
ceph.client.nova.keyring #################################创建成功############################ \033[0m"
fi
}

scp_deploy_keys() {
echo -e "\033[${yellow} 创建所需目录 \033[0m"
mkdir -p /etc/kolla/config/nova
mkdir -p /etc/kolla/config/cinder
mkdir -p /etc/kolla/config/cinder/{cinder-volume,cinder-backup}
mkdir -p /etc/kolla/config/glance
echo -e "\033[${green} 所需目录创建成功 \033[0m"

echo -e "\033[${yellow} 开始执行将文件${ceph_file} 传输部署节点(kolla-ansible所在节点) \033[0m"
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/glance/
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/cinder/cinder-volume/
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/cinder/cinder-backup/
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/cinder/cinder-backup/
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/nova/
scp /etc/ceph/* ${deploy_host}://etc/kolla/config/cinder
echo -e "\033[${green} 文件${ceph_file}
传输到 部署节点(kolla-ansible所在节点) 成功 \033[0m"
}
create_files() {
echo -e "\033[${yellow} 编写所需文件 \033[0m"
cat << EOF > /etc/kolla/config/nova/nova-compute.conf
[libvirt]
virt_type=qemu
cpu_mode = none
images_rbd_pool=vms
images_type=rbd
images_rbd_ceph_conf=/etc/ceph/ceph.conf
rbd_user=nova
EOF
cat > /etc/kolla/config/glance/glance-api.conf << eric
[glance_store]
stores=rbd
default_store=rbd
rbd_store_pool=images
rbd_store_user=glance
rbd_store_ceph_conf=/etc/ceph/ceph.conf
eric
cat > /etc/kolla/config/cinder/cinder-volume.conf << eric
[DEFAULT]
enabled_backends=rbd-1
[rbd-1]
rbd_ceph_conf=/etc/ceph/ceph.conf
rbd_user=cinder
backend_host=rbd:volumes
rbd_pool=volumes
volume_backend_name=rbd-1
volume_driver=cinder.volume.drivers.rbd.RBDDriver
rbd_secret_uuid=${rbd_secret_uuid}
eric
cat > /etc/kolla/config/cinder/cinder-backup.conf << eric
[DEFAULT]
backup_ceph_conf=/etc/ceph/ceph.conf
backup_ceph_user=cinder-backup
backup_ceph_chunk_size=134217728
backup_ceph_pool=backups
backup_driver=cinder.backup.drivers.ceph.CephBackupDriver
backup_ceph_stripe_unit=0
backup_ceph_stripe_count=0
restore_discard_excess_bytes=true
eric
echo -e "\033[${green} 所需文件编入完成 \033[0m"
}
main() {
create_keys # 创建密钥
scp_deploy_keys # 传输密钥
create_files # 创建kolla-ansible配置文件
}
main

image-20231203180634002

fighting!