2021년 10월 15일 금요일

OpenStack backend 스토리지로 Ceph 사용하기

전제 조건

  • 오픈스택이 이미 구성되어 있음
  • Ceph 클러스터도 이미 구성되어 있음

ceph 노드 수정

  • ceph node 들의 hosts 파일에 openstack 노드 정보 입력
# vi /etc/hosts 10.10.10.74 cont30.mytec.com cont30 10.10.10.77 comp1.mytec.com comp1 10.10.10.78 comp2.mytec.com comp2

openstack 을 위한 pool 생성

  • cinder, glance 를 위한 pool 생성
    • ceph admin node 에서 실행
ceph osd pool create volumes ceph osd pool create images ceph osd pool create backups ceph osd pool create vms
  • rbd tool 을 사용해서 pool 들을 initialize 함
    • 새로 생성된 pool 들은 사용하기 전에 initialize 되어야 함
rbd pool init volumes rbd pool init images rbd pool init backups rbd pool init vms

openstack ceph clients 환경 설정

  • glance-api, cinder-volume, nova-compute, cinder-backup 를 실행하는 노드들은 Ceph client 로 동작해야 함
  • 따라서 ceph.conf 파일이 필요함
    • 각 노드에서 아래 실행
for NODE in comp1 comp2 cont30 do scp /etc/ceph/ceph.conf $NODE:/etc/ceph/ done
  • ceph client 패키지 설치

    • glance-api 노드에서 python-rbd 설치
    sudo yum install python-rbd
    • nova-compute, cinder-backup, cinder-volume node 에서 ceph-common 설치
    sudo yum install ceph-common

Setup Ceph Client Authentication

ceph auth get-or-create client.glance mon 'profile rbd' osd 'profile rbd pool=images' mgr 'profile rbd pool=images' ceph auth get-or-create client.cinder mon 'profile rbd' osd 'profile rbd pool=volumes, profile rbd pool=vms, profile rbd-read-only pool=images' mgr 'profile rbd pool=volumes, profile rbd pool=vms' ceph auth get-or-create client.cinder-backup mon 'profile rbd' osd 'profile rbd pool=backups' mgr 'profile rbd pool=backups'
  • client.cinder, client.glance, client.cinder-backup 용 keyring 를 필요로 하는 오픈스택 노드에 추가하고 owernership 변경함
    • ceph admin 노드에서 실행
# cont30 is openstack controller node ceph auth get-or-create client.glance | ssh cont30 sudo tee /etc/ceph/ceph.client.glance.keyring ssh cont30 sudo chown glance:glance /etc/ceph/ceph.client.glance.keyring ceph auth get-or-create client.cinder | ssh cont30 sudo tee /etc/ceph/ceph.client.cinder.keyring ssh cont30 sudo chown cinder:cinder /etc/ceph/ceph.client.cinder.keyring ceph auth get-or-create client.cinder-backup | ssh cont30 sudo tee /etc/ceph/ceph.client.cinder-backup.keyring ssh cont30 sudo chown cinder:cinder /etc/ceph/ceph.client.cinder-backup.keyring
  • nova-compute 노드에서 필요로 하는 keyring 파일 전달
ceph auth get-or-create client.cinder | ssh comp1 sudo tee /etc/ceph/ceph.client.cinder.keyring ceph auth get-or-create client.cinder | ssh comp2 sudo tee /etc/ceph/ceph.client.cinder.keyring
  • 오픈스택 노드에 대해 secret key 에 대한 임시 카피본 생성
# cont30: controller node, comp1, 2: compute node ceph auth get-key client.cinder | ssh cont30 tee client.cinder.key ceph auth get-key client.cinder | ssh comp1 tee client.cinder.key ceph auth get-key client.cinder | ssh comp2 tee client.cinder.key
  • compute 노드에서 secret 키를 libvirt 에 추가하고 임시 카피본 삭제함
    • 각 compute 노드에서 실행함
    • uuidgen 으로 나온 값은 하나만 가지고 계속 사용해야 하므로 잘 기록해둘 것
# uuidgen 66263415-483a-4450-bd89-a0c036fb8f8c cat > secret.xml <<EOF <secret ephemeral='no' private='no'> <uuid>66263415-483a-4450-bd89-a0c036fb8f8c</uuid> <usage type='ceph'> <name>client.cinder secret</name> </usage> </secret> EOF # sudo virsh secret-define --file secret.xml Secret 457eb676-33da-42ec-9a8c-9293d545c337 created # sudo virsh secret-set-value --secret 66263415-483a-4450-bd89-a0c036fb8f8c --base64 $(cat client.cinder.key) && rm client.cinder.key secret.xml

Ceph 을 사용하기 위해 오픈스택 구성하기

  • Glance 환경 설정
    • Glance 는 이미지들을 저정하기 위해 멀티 backend 를 사용할 수 있음
    • Ceph block 디바이스를 디폴트로 사용하기 위해 glance 를 아래와 같이 수정함
# 컨트롤러 노드의 ceph.conf 를 수정해야 함 # vi /etc/ceph/ceph.conf [client.glance] keyring = /etc/ceph/ceph.client.glance.keyring
  • /etc/glance/glance-api.conf 열어서 아래와 같이 [glance_store] section 추가
[glance_store] stores = rbd default_store = rbd rbd_store_pool = images rbd_store_user = glance rbd_store_ceph_conf = /etc/ceph/ceph.conf rbd_store_chunk_size = 8
  • glance 에 있는 image 들의 copy-on-write cloning 을 사용고자 한다면, glance-api.conf 의 [DEFAULT] section 에서 아래 항목 추가
show_image_direct_url = True
  • Cache management 비활성화
    • Disable the Glance cache management to avoid images getting cached under /var/lib/glance/image-cache/
      • flavor = keystone+cachemanagement 로 되어있다면 아래와 같이 변경함
[paste_deploy] flavor = keystone
  • cinder 노드 환경 설정
    • openstack 이 Ceph block device 를 사용하기 위해서는 driver 가 필요함
    • 또한 이 block device 를 위한 pool name 도 지정해야 함
    • 따라서 오픈스택 cinder 노드에서 아래와 같이 /etc/cinder/cinder.conf 를 수정해야 함
[DEFAULT] ... enabled_backends = ceph glance_api_version = 2 ... [ceph] volume_driver = cinder.volume.drivers.rbd.RBDDriver volume_backend_name = ceph rbd_pool = volumes rbd_ceph_conf = /etc/ceph/ceph.conf rbd_flatten_volume_from_snapshot = false rbd_max_clone_depth = 5 rbd_store_chunk_size = 4 rados_connect_timeout = -1 rbd_user = cinder rbd_secret_uuid = 66263415-483a-4450-bd89-a0c036fb8f8c
  • cinder backup 노드 환경 설정
    • cinder backup 노드에서 /etc/cinder/cinder.conf 를 아래와 같이 수정
backup_driver = cinder.backup.drivers.ceph.CephBackupDriver backup_ceph_conf = /etc/ceph/ceph.conf backup_ceph_user = cinder-backup backup_ceph_chunk_size = 134217728 backup_ceph_pool = backups backup_ceph_stripe_unit = 0 backup_ceph_stripe_count = 0 restore_discard_excess_bytes = true
  • ceph rbd block device 를 attach 하기 위한 nova 노드 환경 설정
    • cinder 디바이스를 붙이기 위해 nova 하고 libvirt 에게 user, uuid 정보를 알려주어야 함
    • 이 정보를 이용해서 ceph cluster 와 통신함
      • /etc/nova/nova.conf 수정
[libvirt] ... rbd_user = cinder rbd_secret_uuid = 66263415-483a-4450-bd89-a0c036fb8f8c
  • nova 환경 설정

    • To enable RBD cache and admin sockets, ensure that on each hypervisor’s ceph.conf contains:
    • RBD cache 와 admin socket 활성화를 위해 ceph.conf 수정 (모든 compute node)
    [client] rbd cache = true rbd cache writethrough until flush = true admin socket = /var/run/ceph/guests/$cluster-$type.$id.$pid.$cctid.asok log file = /var/log/qemu/qemu-guest-$pid.log rbd concurrent management ops = 20
    • 디렉토리 권한 설정
mkdir -p /var/run/ceph/guests/ /var/log/qemu/ chown qemu:libvirtd /var/run/ceph/guests /var/log/qemu/ 위 명령 에러나면 아래로 변경 chown qemu:libvirt /var/run/ceph/guests /var/log/qemu/
  • 오픈스택 재시작
    • Ceph block 디바이스 드라이버를 활성화시키고 block device pool 을 사용하기 위해 관련된 오픈스택 데몬들을 재시작 해야 함

(모든 노드, 없는 서비스는 알아서 에러 날 것이나 무시하면 됨)

sudo service openstack-glance-api restart sudo service openstack-nova-compute restart sudo service openstack-cinder-volume restart sudo service openstack-cinder-backup restart

openstack 으로 ceph 테스트 하기

  • ceph 테스트로 사용할 이미지 생성
    • cirros 이미지는 검색하면 다 나옴
cirros-0.5.2-x86_64-disk.img 다운로드 아래 명령어 실행하기 전에 source keystonerc_admin 식의 명령어 실행으로 openstack 환경 sourcing 해야 함 # openstack image create --disk-format qcow2 --container-format bare --public --file cirros-0.5.2-x86_64-disk.img cirros2
  • 오픈스택 접속해서 위에서 만든 이미지 가지고 VM 생성 시도

    • 에러 나는 경우, cinder.conf 의 default_volume_type 을 ceph 으로 변경하고 cinder 서비스 재시작 하고 아래 명령어 실행
    sudo service openstack-cinder-api restart # openstack volume type create ceph # openstack volume type set --property volume_backend_name=ceph ceph # 아래 명령어 결과에서 ceph 정보가 있는지 확인 # cinder type-default # cinder type-list # cinder extra-specs-list
    • 위와 같이 해도 인스턴스 생성 에러 발생할 경우, 볼륨 생성만 따로 해보던지 해서 문제를 좁힘
    • nova log 나 cinder log 보고 인증 쪽 오류이면 위의 key 생성을 관련 호스트들에 대해서 제대로 했는지 확인

2021년 10월 7일 목요일

Install OpenStack Victoria on CentOS 8

 

  • VM 3개를 준비함 (controller, compute1, compute2)
    • controller : 4vCPU, 8GB
      • vdisk1 : 200GB
      • vdisk2 : 40GB (cinder 용)
      • vNIC1 : 사설 관리망(인터넷 안됨, 예: 10.10.10.0/24)
      • vNIC2 : OpenStack 에서 생성한 VM 에게 부여할 사설 IP(인터넷 안됨, 예: 20.20.20.0/24)
      • vNIC3: 외부망(인터넷 됨: 예: 172.16.10.0/24)
    • compute1, 2: 4vCPU, 8GB
      • vdisk1 : 200GB
      • vNIC1 : 사설 관리망(인터넷 안됨, 예: 10.10.10.0/24)
      • vNIC2 : OpenStack 에서 생성한 VM 에게 부여할 사설 IP(인터넷 안됨, 예: 20.20.20.0/24)
      • vNIC3: 외부망(인터넷 됨: 예: 172.16.10.0/24)

  • 모든 노드에 대해 hostname 설정
sudo hostnamectl set-hostname cont30.mytec.com
sudo hostnamectl set-hostname comp1.mytec.com
sudo hostnamectl set-hostname comp2.mytec
.com

  • 각 노드의 /etc/hosts 파일 수정
    • public ip 가 아닌 priviate ip 로 함
# vim /etc/hosts
10.10.10.x	cont30.mytec.com	cont30
10.10.10.y comp1.mytec.com comp1
10.10.10.z comp2.mytec
.com comp2
  • Disable IPv6 (모든 노드)
# vim /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1

아래 명령어로 확인
# sysctl -p
  • Set Max PID (모든 노드)
# echo kernel.pid_max = 65536 >> /etc/sysctl.conf

아래 명령어로 확인
# sysctl -p

  • disable SELINUX (모든 노드)
# setenforce 0

Modify 'SELINUX=disabled' in the file '/etc/sysconfig/selinux' to disable permanently.

# vim /etc/sysconfig/selinux
SELINUX=disabled

(여기까지 하고 VM snapshot 뜨는 것도 좋음)

  • install network-scripts
  • disable firewalld and NetworkManager and then enable network
sudo dnf install -y network-scripts
sudo systemctl disable --now firewalld NetworkManager
sudo systemctl enable network && sudo systemctl start network

  • Disable deprecated warnings:
sudo touch /etc/sysconfig/disable-deprecation-warnings

  • network 서비스 상태 확인
systemctl status network
  • updatesystem and install basic utilities
sudo dnf -y install vim wget curl telnet bash-completion network-scripts dnf-utils

  • OpenStack Victoria 또는 특정 release repository 추가
    • 더 최신 release 가 있다면 그것도 가능
sudo dnf config-manager --enable powertools
또는 dnf config-manager --enable PowerTools

sudo dnf install -y centos-release-openstack-victoria
또는
sudo dnf install -y centos-release-openstack-ussuri

sudo dnf -y update
  • install packstack package for CentOS.
# sudo dnf install -y openstack-packstack

위 명령 에러나면 아래 참고해서 troubleshooting

wget https://cbs.centos.org/kojifiles/packages/puppet-xinetd/3.3.0/2.8d460c4git.el8/noarch/puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm
rpm -Uvh puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm
rpm -Uvh https://yum.puppet.com/puppet6-release-el-8.noarch.rpm
yum repolist
rpm -Uvh puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm
yum install -y puppetserver
rpm -Uvh puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm

[root@openstack openstack]# rpm -Uvh puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm
error: Failed dependencies:
puppet-stdlib is needed by puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch

wget http://repos2.reduniv.edu.cu/REPOSITORIOS_SWL/CENTOS/centos/8/cloud/x86_64/openstack-ussuri/Packages/p/puppet-stdlib-6.3.0-1.93eee77git.el8.noarch.rpm
rpm -Uvh puppet-stdlib-6.3.0-1.93eee77git.el8.noarch.rpm
rpm -Uvh puppet-xinetd-3.3.0-2.8d460c4git.el8.noarch.rpm
위 명령어 참고해서 troubleshooting 한 다음 아래 명령 다시 시도
# sudo dnf install -y openstack-packstack

아래 명령어 통해 packstack 잘 설치 되었는지 확인
# packstack --version

Enable virt module

sudo dnf -y module enable virt

Update system:

sudo dnf update -y
sudo systemctl reboot

  • Create a PV & VG on Controller node for Cinder backend
아래 3가지는 안해도 될 것 같으나, cinder 를 위한 볼륨이 있다면 하는 것이 좋을 것 같음
pvcreate /dev/sdb
vgcreate cinder-volumes /dev/sdb
reboot
# 위 명령어 시에 아래와 같은 에러 발생한다면 vdisk2 를 생성안 한 것이므로, 2nd vdisk 생성 후 다시 시도함
No device found for /dev/sdb.

  • packstack 에서 사용할 answer 파일 생성 (openstack-answer.txt)
packstack --gen-answer-file=openstack-answer.txt
  • 아래 내용으로 openstack-answer.txt 변경
# 위에서 cinder-volumes 만들었다면
CONFIG_CINDER_VOLUMES_CREATE=n

CONFIG_NEUTRON_ML2_TYPE_DRIVERS=vxlan,flat,vlan
CONFIG_NEUTRON_ML2_TENANT_NETWORK_TYPES=vxlan
CONFIG_NEUTRON_ML2_MECHANISM_DRIVERS=openvswitch
CONFIG_NEUTRON_ML2_TUNNEL_ID_RANGES=10:1000
CONFIG_NEUTRON_L2_AGENT=openvswitch
CONFIG_NEUTRON_OVS_BRIDGE_MAPPINGS=extnet:br-ex
CONFIG_NEUTRON_OVS_BRIDGE_IFACES=br-ex:ens256
CONFIG_NEUTRON_OVS_TUNNEL_IF=ens224
CONFIG_NEUTRON_OVS_TUNNEL_SUBNETS=20.20.20.0/24
CONFIG_NEUTRON_METERING_AGENT_INSTALL=n


# compute host private ip 추가
CONFIG_COMPUTE_HOSTS=10.10.10.60,10.10.10.61

# controller host 에 private ip 가 아닌 public ip 가 설정되어 있다면
# 모든 controller public ip -> private ip 로 변경함
CONFIG_CONTROLLER_HOST=10.10.10.62

# 아니면 controller, compute 등 모든 openstack node 의 ip 를 public ip 로 하는 것도 문제는 없음
sudo packstack --answer-file openstack-answer.txt

아래와 비슷한 화면이 출력됨
Welcome to the Packstack setup utility

The installation log file is available at: /var/tmp/packstack/20211006-021435-bbcro3di/openstack-setup.log

Installing:
Clean Up                                             [ DONE ]
Discovering ip protocol version                      [ DONE ]
Setting up ssh keys                                  [ DONE ]
Preparing servers                                    [ DONE ]
Pre installing Puppet and discovering hosts' details [ DONE ]
Preparing pre-install entries                        [ DONE ]
Setting up CACERT                                    [ DONE ]
Preparing AMQP entries                               [ DONE ]
Preparing MariaDB entries                            [ DONE ]
Fixing Keystone LDAP config parameters to be undef if empty[ DONE ]
Preparing Keystone entries                           [ DONE ]
Preparing Glance entries                             [ DONE ]
Checking if the Cinder server has a cinder-volumes vg[ DONE ]
Preparing Cinder entries                             [ DONE ]
Preparing Nova API entries                           [ DONE ]
Creating ssh keys for Nova migration                 [ DONE ]
Gathering ssh host keys for Nova migration           [ DONE ]
Preparing Nova Compute entries                       [ DONE ]
Preparing Nova Scheduler entries                     [ DONE ]
Preparing Nova VNC Proxy entries                     [ DONE ]
Preparing OpenStack Network-related Nova entries     [ DONE ]
Preparing Nova Common entries                        [ DONE ]
Preparing Neutron API entries                        [ DONE ]
Preparing Neutron L3 entries                         [ DONE ]
Preparing Neutron L2 Agent entries                   [ DONE ]
Preparing Neutron DHCP Agent entries                 [ DONE ]
Preparing Neutron Metering Agent entries             [ DONE ]
Checking if NetworkManager is enabled and running    [ DONE ]
Preparing OpenStack Client entries                   [ DONE ]
Preparing Horizon entries                            [ DONE ]
Preparing Swift builder entries                      [ DONE ]
Preparing Swift proxy entries                        [ DONE ]
Preparing Swift storage entries                      [ DONE ]
Preparing Gnocchi entries                            [ DONE ]
Preparing Redis entries                              [ DONE ]
Preparing Ceilometer entries                         [ DONE ]
Preparing Aodh entries                               [ DONE ]
Preparing Puppet manifests                           [ DONE ]
Copying Puppet modules and manifests                 [ DONE ]

  • 시간 동기화 안되어 있다면 지금이라도 함 (모든 노드)
    • /etc/chrony.conf 수정
    server 172.16.10.254 iburst
    sudo systemctl restart chronyd
    
    아래 명령어로 동기화 여부 확인
    chronyc sources -v
  • 설치 성공시 아래와 같은 화면 나옴
**** Installation completed successfully ******

Additional information:
 * Time synchronization installation was skipped. Please note that unsynchronized time on server instances might be problem for some OpenStack components.
 * File /root/keystonerc_admin has been created on OpenStack client host 172.16.4.154. To use the command line tools you need to source the file.
 * To access the OpenStack Dashboard browse to http://172.16.4.154/dashboard .
Please, find your login credentials stored in the keystonerc_admin in your home directory.
 * The installation log file is available at: /var/tmp/packstack/20210930-141044-htz9ivmn/openstack-setup.log
 * The generated manifests are available at: /var/tmp/packstack/20210930-141044-htz9ivmn/manifests

  • 디폴트로생성되는 openstack network, router 들이 있는지 확인 후, 있으면 일단 제거
openstack network list
openstack router list

openstack network delete <network>
openstack router delete <delete>

삭제 시 에러나면 아래 링크 참고해서 troubleshooting
https://dischord.org/2016/01/05/cleaning-up-after-neutron/

  • 아래와 같이 OpenStack VM 에서 사용할 내부, 외부 네트워크 생성
    • 아래는 overlay network 로 vxlan 을 사용함
* 내부 네트워크 생성
openstack router create router1
openstack network create int_net --provider-network-type vxlan
openstack subnet create int_sub \
 --network int_net --dns-nameserver 172.16.10.254 \
 --subnet-range 20.20.20.0/24 --gateway 20.20.20.1
openstack router add subnet router1 int_sub
 
* 외부 네트워크 생성
openstack network create \
 --provider-physical-network extnet \
 --provider-network-type flat --external ext_net
 
openstack subnet create ext_sub \
 --network ext_net --subnet-range 172.16.4.0/24 \
 --allocation-pool start=172.16.4.221,end=172.16.4.240 \
 --gateway 172.16.4.1 --dns-nameserver 172.16.10.254 --no-dhcp
 
openstack network list
openstack subnet list

openstack network set --external ext_net
neutron router-gateway-set router1 ext_net
openstack router show router1

  • 위 방식으로 network, subnet, router 등 생성 후 VM 생성함
    • VM 생성되면 VM 에 사설 IP 인 20.20.20.xxx 가 붙음
    • 생성된 VM 클릭해서 콘솔로 접속 시도
      • 웹에서 콘솔 접속 하는 IP 10.10.10.xxx 대역의 사설 IP 라서 외부에서 접속이 안될 것이므로 대응되는 172.16.4.xxx 대역으로 접속하면 됨
      • 콘솔 접속 후 VM to 외부 (예: ping 8.8.8.8) ping 하면 성공해야 함
  • 외부에서 ping to VM 하면 안됨
    • 외부 접속을 위해 floating IP 가 필요함
  • VM 에 floating IP 할당함
  • 외부에서 ping to VM's floating IP 하면 성공해야 하나 아마 실패할 것임
    • 실패하면 보안그룹에서 inbound, outbound ICMP, TCP, UDP 규칙을 보고 추가해 주면 됨
  • ping 까지 성공하면 ssh to VM's floating IP 까지 성공해야 함