[root@localhost ~]# source keystonerc_admin
[root@localhost ~(logged)]# [root@localhost ~(logged)]# openstack server list 
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+
| ID                                   | Name    | Status | Networks                             | Image   | Flavor    |
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+
| 41e0a679-c0d8-4140-bfa1-ecac05c61552 | CentOS1 | ACTIVE | mynet2=172.16.223.214, 211.183.3.216 | CentOS7 | m1.xsmall |
| b0b7f1b7-45b5-4bb9-abd5-674b1b34b0fb | CentOS2 | ACTIVE | mynet2=172.16.223.215, 211.183.3.201 | CentOS7 | m1.xsmall |
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+[root@localhost ~(logged)]# openstack server show CentOS1 
+-------------------------------------+----------------------------------------------------------+
| Field                               | Value                                                    |
+-------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig                   | AUTO                                                     |
| OS-EXT-AZ:availability_zone         | nova # compute service(Hypervisor)                       |
| OS-EXT-SRV-ATTR:host                | localhost.localdomain                                    |
| OS-EXT-SRV-ATTR:hypervisor_hostname | localhost.localdomain                                    |
| OS-EXT-SRV-ATTR:instance_name       | instance-00000003                                        |
| OS-EXT-STS:power_state              | Running                                                  |
| OS-EXT-STS:task_state               | None                                                     |
| OS-EXT-STS:vm_state                 | active                                                   |
| OS-SRV-USG:launched_at              | 2022-09-15T08:18:59.000000                               |
| OS-SRV-USG:terminated_at            | None                                                     |
| accessIPv4                          |                                                          |
| accessIPv6                          |                                                          |
| addresses                           | mynet2=172.16.223.214, 211.183.3.216                     |
| config_drive                        |                                                          |
| created                             | 2022-09-15T08:18:37Z                                     |
| flavor                              | m1.xsmall (6)                                            |
| hostId                              | eb167483365e65c5f00c79834d44bd79954cddfdd5367607b11cff2c |
| id                                  | 41e0a679-c0d8-4140-bfa1-ecac05c61552                     |
| image                               | CentOS7 (e0c0a34f-9d31-47cc-b9a5-060bf8d55446)           |
| key_name                            | chulsookey                                               |
| name                                | CentOS1                                                  |
| progress                            | 0                                                        |
| project_id                          | c40873732ac9467aba534da6e8f7a4ec                         |
| properties                          |                                                          |
| security_groups                     | name='permitweb'                                         |
| status                              | ACTIVE                                                   |
| updated                             | 2022-09-15T23:52:42Z                                     |
| user_id                             | 327feb443acc4995b4dfd7081a67d4da                         |
| volumes_attached                    |                                                          |
+-------------------------------------+----------------------------------------------------------+[root@localhost ~(logged)]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 1     instance-00000003              running
 2     instance-00000002              running[root@localhost ~(logged)]# openstack server start CentOS1
[root@localhost ~(logged)]# openstack server start CentOS2[root@localhost ~(logged)]# virsh console instance-00000003
Connected to domain instance-00000003
Escape character is ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-1127.el7.x86_64 on an x86_64
centos1 login:[root@localhost ~(logged)]# openstack server migrate CentOS1 \
> --live \
> localhost.localdomain
Unable to migrate instance (41e0a679-c0d8-4140-bfa1-ecac05c61552) to current host (localhost.localdomain). (HTTP 400) (Request-ID: req-bc27a558-140e-4e76-9722-267464a83746)
- --live: 동작 중인 상태에서 migrate
- localhost.localdomain으로 이동
One node 환경에서 실습 중이기 때문에, 자기 자신에게 migrage할 수 없음.
[root@localhost ~(logged)]# nova live-migration CentOS1nova가 호스트들의 자원 사용률을 비교해서 migration 진행
방법 1) ssh(CLI)를 이용. private key가 필요하다.
[root@localhost ~]# ssh -i ~/.ssh/chulsoo.pem -l centos 211.183.3.216
The authenticity of host '211.183.3.216 (211.183.3.216)' can't be established.
ECDSA key fingerprint is SHA256:HA66XnMZeQzjA3dhnNeaCyi0mrDd+3yIQxHigSgrsII.
ECDSA key fingerprint is MD5:da:d6:dc:e4:68:c1:fd:fd:89:e7:af:d5:82:3d:f8:de.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '211.183.3.216' (ECDSA) to the list of known hosts.
Last login: Fri Sep 16 00:02:41 2022 from 211.183.3.1
[centos@centos1 ~]$ ssh -i ~/.ssh/chulsoo.pem -l centos 211.183.3.216
- -l: 유저(centos) 입력
방법 2) vnc(GUI)를 이용
211.183.3.111에서 proxy를 제공한다. 
[root@localhost ~(logged)]# openstack console url show CentOS1 | grep url 
| url   | http://211.183.3.111:6080/vnc_auto.html?path=%3Ftoken%3D5a523733-6c33-4ef1-8757-fc1e29c52b9c |
참고: https://docs.openstack.org/mitaka/ko_KR/install-guide-obs/glance-verify.html
[root@localhost 0916(logged)]# wget http://download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img
--2022-09-16 10:34:24--  http://download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img
Resolving download.cirros-cloud.net (download.cirros-cloud.net)... 64.90.42.85, 2607:f298:6:a036::bd6:a72a
Connecting to download.cirros-cloud.net (download.cirros-cloud.net)|64.90.42.85|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/cirros-dev/cirros/releases/download/0.5.1/cirros-0.5.1-x86_64-disk.img [following]
--2022-09-16 10:34:25--  https://github.com/cirros-dev/cirros/releases/download/0.5.1/cirros-0.5.1-x86_64-disk.img
Resolving github.com (github.com)... 20.200.245.247
Connecting to github.com (github.com)|20.200.245.247|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/219785102/6ebfbc00-5fb5-11ea-91bd-96a6baa1496d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220916%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220916T013336Z&X-Amz-Expires=300&X-Amz-Signature=7c1eb848defdc0ffef65fc8578f1baac603d0c02536c81186e08d2e92288dff9&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=219785102&response-content-disposition=attachment%3B%20filename%3Dcirros-0.5.1-x86_64-disk.img&response-content-type=application%2Foctet-stream [following]
--2022-09-16 10:34:26--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/219785102/6ebfbc00-5fb5-11ea-91bd-96a6baa1496d?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20220916%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20220916T013336Z&X-Amz-Expires=300&X-Amz-Signature=7c1eb848defdc0ffef65fc8578f1baac603d0c02536c81186e08d2e92288dff9&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=219785102&response-content-disposition=attachment%3B%20filename%3Dcirros-0.5.1-x86_64-disk.img&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.109.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 16338944 (16M) [application/octet-stream]
Saving to: ‘cirros-0.5.1-x86_64-disk.img’
100%[=====================================================================================================================================================================>] 16,338,944  1.28MB/s   in 9.4s   
2022-09-16 10:34:35 (1.66 MB/s) - ‘cirros-0.5.1-x86_64-disk.img’ saved [16338944/16338944][root@localhost 0916(logged)]# openstack image create "CIRROS" \
> --file cirros-0.5.1-x86_64-disk.img \
> --disk-format qcow2 \
> --container-format bare \
> --public
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 1d3062cd89af34e419f7100277f38b2b                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2022-09-16T01:38:32Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/e4a5f612-cd02-492c-8346-4eff746e6aa5/file                                                                                                                                       |
| id               | e4a5f612-cd02-492c-8346-4eff746e6aa5                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | CIRROS                                                                                                                                                                                     |
| owner            | c40873732ac9467aba534da6e8f7a4ec                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='553d220ed58cfee7dafe003c446a9f197ab5edf8ffc09396c74187cf83873c877e7ae041cb80f3b91489acf687183adcd689b53b38e3ddd22e627e7f98a09c46', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 16338944                                                                                                                                                                                   |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2022-09-16T01:38:33Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+[root@localhost 0916(logged)]# openstack image list
+--------------------------------------+---------+--------+
| ID                                   | Name    | Status |
+--------------------------------------+---------+--------+
| e4a5f612-cd02-492c-8346-4eff746e6aa5 | CIRROS  | active |
| e0c0a34f-9d31-47cc-b9a5-060bf8d55446 | CentOS7 | active |
+--------------------------------------+---------+--------+[root@localhost 0916(logged)]# openstack flavor list 
+----+-----------+-------+------+-----------+-------+-----------+
| ID | Name      |   RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+-----------+-------+------+-----------+-------+-----------+
| 1  | m1.tiny   |   512 |    1 |         0 |     1 | True      |
| 2  | m1.small  |  2048 |   20 |         0 |     1 | True      |
| 3  | m1.medium |  4096 |   40 |         0 |     2 | True      |
| 4  | m1.large  |  8192 |   80 |         0 |     4 | True      |
| 5  | m1.xlarge | 16384 |  160 |         0 |     8 | True      |
| 6  | m1.xsmall |  1024 |   20 |         0 |     1 | True      |
+----+-----------+-------+------+-----------+-------+-----------+DB 인스턴스를 만들기에 m1.tiny면 충분하다.
[root@localhost 0916(logged)]# openstack network list 
+--------------------------------------+--------+--------------------------------------+
| ID                                   | Name   | Subnets                              |
+--------------------------------------+--------+--------------------------------------+
| 6eb1671b-bc5a-40ab-9a60-3351021cf149 | mynet1 | bf8b842c-44d9-437a-95b8-d4b6c4a82175 |
| 8fa04edd-74d8-4909-ac39-8e121b7c21f7 | extnet | a136d9a3-d564-4f19-b272-86c3b46a792b |
| bf8a8a47-8bd6-438c-82c9-0c87cb0c3a04 | mynet2 | bc57a0c2-ba29-42ba-9c5b-5c2f2802663d |
+--------------------------------------+--------+--------------------------------------+mynet1에 DB를 생성할 것이다.
[root@localhost 0916(logged)]# openstack server create \
> --flavor m1.tiny \
> --image CIRROS \
> --nic net-id=6eb1671b-bc5a-40ab-9a60-3351021cf149 \
> --security-group permitweb \
> TESTDB
+-------------------------------------+-----------------------------------------------+
| Field                               | Value                                         |
+-------------------------------------+-----------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                        |
| OS-EXT-AZ:availability_zone         |                                               |
| OS-EXT-SRV-ATTR:host                | None                                          |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                          |
| OS-EXT-SRV-ATTR:instance_name       |                                               |
| OS-EXT-STS:power_state              | NOSTATE                                       |
| OS-EXT-STS:task_state               | scheduling                                    |
| OS-EXT-STS:vm_state                 | building                                      |
| OS-SRV-USG:launched_at              | None                                          |
| OS-SRV-USG:terminated_at            | None                                          |
| accessIPv4                          |                                               |
| accessIPv6                          |                                               |
| addresses                           |                                               |
| adminPass                           | Fr9kShYguGPf                                  |
| config_drive                        |                                               |
| created                             | 2022-09-16T01:47:12Z                          |
| flavor                              | m1.tiny (1)                                   |
| hostId                              |                                               |
| id                                  | c2f9d938-f96d-448a-b91f-cc5bfa8b6113          |
| image                               | CIRROS (e4a5f612-cd02-492c-8346-4eff746e6aa5) |
| key_name                            | None                                          |
| name                                | TESTDB                                        |
| progress                            | 0                                             |
| project_id                          | c40873732ac9467aba534da6e8f7a4ec              |
| properties                          |                                               |
| security_groups                     | name='7ed5ded2-a663-45a5-99b7-dfb96a915d08'   |
| status                              | BUILD                                         |
| updated                             | 2022-09-16T01:47:12Z                          |
| user_id                             | 327feb443acc4995b4dfd7081a67d4da              |
| volumes_attached                    |                                               |
+-------------------------------------+-----------------------------------------------+[root@localhost 0916(logged)]# openstack server list 
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+
| ID                                   | Name    | Status | Networks                             | Image   | Flavor    |
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+
| c2f9d938-f96d-448a-b91f-cc5bfa8b6113 | TESTDB  | ACTIVE | mynet1=172.16.123.7                  | CIRROS  | m1.tiny   |
| 41e0a679-c0d8-4140-bfa1-ecac05c61552 | CentOS1 | ACTIVE | mynet2=172.16.223.214, 211.183.3.216 | CentOS7 | m1.xsmall |
| b0b7f1b7-45b5-4bb9-abd5-674b1b34b0fb | CentOS2 | ACTIVE | mynet2=172.16.223.215, 211.183.3.201 | CentOS7 | m1.xsmall |
+--------------------------------------+---------+--------+--------------------------------------+---------+-----------+TESTDB가 생성되었음. IP는 172.16.123.7



[centos@centos1 ~]$ ping 172.16.123.7 -c 3
PING 172.16.123.7 (172.16.123.7) 56(84) bytes of data.
64 bytes from 172.16.123.7: icmp_seq=1 ttl=62 time=3.34 ms
64 bytes from 172.16.123.7: icmp_seq=2 ttl=62 time=1.14 ms
64 bytes from 172.16.123.7: icmp_seq=3 ttl=62 time=1.04 ms
--- 172.16.123.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.048/1.843/3.341/1.059 ms[centos@centos2 ~]$ ping 172.16.123.7 -c 3
PING 172.16.123.7 (172.16.123.7) 56(84) bytes of data.
64 bytes from 172.16.123.7: icmp_seq=1 ttl=62 time=9.85 ms
64 bytes from 172.16.123.7: icmp_seq=2 ttl=62 time=1.09 ms
64 bytes from 172.16.123.7: icmp_seq=3 ttl=62 time=1.28 ms
--- 172.16.123.7 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2006ms
rtt min/avg/max/mdev = 1.091/4.077/9.859/4.089 ms


fore는 http로 접속이 들어옴
```python 
ex) source ip의 끝 자리 비트를 보는 규칙 
출발지 IP
1.1.1.1 (1 = 0000 000"1" => 서버 1) 
1.1.1.3 (3 = 0000 001"1" => 서버 1) 
1.1.1.8 (8 = 0000 100"0" => 서버 2)
```

만약 인스턴스의 성능에 차이가 있다면, 성능이 더 좋은 인스턴스에 가중치를 줄 수도 있음.
CentOS1, CentOS2 추가

HTTP GET metnod로 특정 url에 접속하여 웹페이지가 열리는지 확인함

기존의 floating ip 선택

Round Robin 방식 동작 확인


[centos@centos1 html]$ sudo rm -f index.html 
CentOS2 페이지로만 접속된다.
health check 방식이 ping이 아닌, HTTP ur을 체크하는 방식이므로,
CentOS1 인스턴스로의 접속은 안 한다.
[centos@centos1 ~]$ df -h 
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        473M     0  473M   0% /dev
tmpfs           496M     0  496M   0% /dev/shm
tmpfs           496M   13M  483M   3% /run
tmpfs           496M     0  496M   0% /sys/fs/cgroup
/dev/vda1        20G  1.0G   19G   5% /
tmpfs           100M     0  100M   0% /run/user/1000[centos@centos1 ~]$ ls /dev/vd* 
/dev/vda  /dev/vda1인스턴스 3개
CentOS1 -> disk: 20GB 자신이 속해있는 호스트의 로컬 디스크를 사용하고 있다. 
참고: https://docs.openstack.org/cinder/latest/cli/cli-manage-volumes.html
block storage: Cinder
볼륨 생성

인스턴스 생성

[root@localhost ~]# yum -y install libvirt qemu-kvm virt-install 
- libvirt
- qemu-kvm
- virt-install
[root@localhost ~]# systemctl enable libvirtd --now[root@localhost ~]# yum -y install libguestfs-tools libguestfs-tools에는 virt-resize, virt-customize 등이 포함되어있음
[root@localhost ~]# cp CentOS-7-x86_64-GenericCloud-2003.qcow2 centos1.qcow2참고: https://velog.io/@ptah0414/KVM-22-08-10-TIL#virt-builder-옵션
[root@localhost ~]# touch index.html 
[root@localhost ~]# echo "<h2>CENTOS</h2>" > index.html --run-command 'systemctl enable httpd' => (o)
--run-command 'systemctl start httpd' => (x)[root@localhost ~]# vi a.sh 
[root@localhost ~]# chmod 777 a.sh #!/bin/bash 
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 
yum -y install docker
systemctl start docker
systemctl enable docker [root@localhost ~]# export LIBGUESTFS_BACKEND=direct[root@localhost ~]# virt-customize \
-a centos1.qcow2 \
--update \
--install httpd \
--upload index.html:/var/www/html/index.html \
--run-command 'systemctl enable httpd' \
--root-password password:test123 \
--run './a.sh' \
--selinux-relabel 
[   0.0] Examining the guest ...
[   7.0] Setting a random seed
[   7.1] Updating packages
[ 159.5] Installing packages: httpd
[ 165.1] Uploading: index.html to /var/www/html/index.html
[ 165.1] Running: systemctl enable httpd
[ 165.2] Running: ./a.sh
[ 181.6] Setting passwords
[ 182.9] SELinux relabelling
[ 190.2] Finishing off[root@localhost ~]# source keystonerc_admin 
[root@localhost ~(logged)]# [root@localhost ~(logged)]# openstack image create "centos1" \
--file centos1.qcow2 \
--disk-format qcow2 \
--container-format bare \
--public
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field            | Value                                                                                                                                                                                      |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum         | 1707d9c5607f6e229dc82bfa608aa8af                                                                                                                                                           |
| container_format | bare                                                                                                                                                                                       |
| created_at       | 2022-09-16T08:41:57Z                                                                                                                                                                       |
| disk_format      | qcow2                                                                                                                                                                                      |
| file             | /v2/images/90e5abc6-140d-49bc-82dc-139396fcd398/file                                                                                                                                       |
| id               | 90e5abc6-140d-49bc-82dc-139396fcd398                                                                                                                                                       |
| min_disk         | 0                                                                                                                                                                                          |
| min_ram          | 0                                                                                                                                                                                          |
| name             | centos1                                                                                                                                                                                    |
| owner            | c40873732ac9467aba534da6e8f7a4ec                                                                                                                                                           |
| properties       | os_hash_algo='sha512', os_hash_value='e6915737e47295291731236b55db97faf31d029ad4afcb0c0d4175231c9a817271f13d871ba0adfd518f6e7be12706f50d3061beb06f3e9bbb3052882f1c34a3', os_hidden='False' |
| protected        | False                                                                                                                                                                                      |
| schema           | /v2/schemas/image                                                                                                                                                                          |
| size             | 2220425216                                                                                                                                                                                 |
| status           | active                                                                                                                                                                                     |
| tags             |                                                                                                                                                                                            |
| updated_at       | 2022-09-16T08:42:29Z                                                                                                                                                                       |
| virtual_size     | None                                                                                                                                                                                       |
| visibility       | public                                                                                                                                                                                     |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@localhost ~(logged)]# 
이름: manager
소스: CentOS7httpd
크기: 20GB

이름: worker
소스: CentOS7httpd
크기: 20GB