2. Openstack Image, Flavor, Network, VM 순차적으로 생성하기
Openstack 인프라 구성이 완료된 상태에서 진행합니다.
참고 : https://sysdocu.tistory.com/1833
1. 이미지 생성
OS 설치용 이미지를 Openstack 에 등록해야 합니다.
CentOS 7 cloud 버전 이미지를 다운로드 합니다.
# wget https://mirrors.cloud.tencent.com/centos-cloud/centos/7/images/CentOS-7-x86_64-GenericCloud-2009.qcow2
이미지 파일을 등록합니다.
# openstack image create "CentOS7" --file CentOS-7-x86_64-GenericCloud-2009.qcow2 --disk-format qcow2 --container-format bare --public
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
| container_format | bare |
| created_at | 2023-07-10T01:23:08Z |
| disk_format | qcow2 |
| file | /v2/images/acbe118e-6881-4ecf-8447-868864150c81/file |
| id | acbe118e-6881-4ecf-8447-868864150c81 |
| min_disk | 0 |
| min_ram | 0 |
| name | CentOS7 |
| owner | 677861619c5445368a353ebeb0bcba2b |
| properties | os_hidden='False', owner_specified.openstack.md5='', owner_specified.openstack.object='images/CentOS7', owner_specified.openstack.sha256='' |
| protected | False |
| schema | /v2/schemas/image |
| status | queued |
| tags | |
| updated_at | 2023-07-10T01:23:08Z |
| visibility | public |
+------------------+---------------------------------------------------------------------------------------------------------------------------------------------+
생성된 이미지를 확인합니다.
# openstack image list
+--------------------------------------+---------+--------+
| ID | Name | Status |
+--------------------------------------+---------+--------+
| acbe118e-6881-4ecf-8447-868864150c81 | CentOS7 | active |
+--------------------------------------+---------+--------+
* Ubuntu Cloud 이미지는 아래 공식 사이트에서 다운로드가 가능합니다.
https://cloud-images.ubuntu.com/
2. Flavor 생성
Flavor는 VM의 리소스 (CPU, 메모리, 디스크 등) 와 구성을 정의 합니다.
Flavor 를 생성합니다.
형식) openstack flavor create --ram <RAM> --disk <DISK> --vcpus <VCPUS> --public <FLAVOR_NAME>
# openstack flavor create --ram 2048 --disk 20 --vcpus 2 --public myflavor
+----------------------------+--------------------------------------+
| Field | Value |
+----------------------------+--------------------------------------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | 0 |
| disk | 20 |
| id | 7e94605d-ace3-4980-94ad-fa49b36c4735 |
| name | myflavor |
| os-flavor-access:is_public | True |
| properties | |
| ram | 2048 |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | 2 |
+----------------------------+--------------------------------------+
생성된 Flavor 를 확인합니다.
# openstack flavor list
+--------------------------------------+----------+------+------+-----------+-------+-----------+
| ID | Name | RAM | Disk | Ephemeral | VCPUs | Is Public |
+--------------------------------------+----------+------+------+-----------+-------+-----------+
| 7e94605d-ace3-4980-94ad-fa49b36c4735 | myflavor | 2048 | 20 | 0 | 2 | True |
+--------------------------------------+----------+------+------+-----------+-------+-----------+
3. Network 생성
먼저 기본 provider 네트워크를 생성합니다.
# openstack network create --share --external --provider-physical-network provider --provider-network-type flat provider
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2023-07-17T06:08:56Z |
| description | |
| dns_domain | None |
| id | b536c267-4a33-4068-a0da-4748a1cbfc97 |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | False |
| is_vlan_transparent | None |
| mtu | 1550 |
| name | provider |
| port_security_enabled | True |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| provider:network_type | flat |
| provider:physical_network | provider |
| provider:segmentation_id | None |
| qos_policy_id | None |
| revision_number | 1 |
| router:external | External |
| segments | None |
| shared | True |
| status | ACTIVE |
| subnets | |
| tags | |
| updated_at | 2023-07-17T06:08:56Z |
+---------------------------+--------------------------------------+
* 옵션 설명
--share : 모든 프로젝트가 가상 네트워크 사용하도록 허용
--external : 가상 네트워크가 외부에 연결되도록 함 (내부 네트워크 사용시 --internal)
다음 파일에 옵션이 설정되었는지 확인하고 없으면 입력합니다.
# vi /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2_type_flat]
flat_networks = provider
# vi /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = provider:eno1
위 eno1 은 네트워크 장치명입니다.
설정이 변경된 경우 neutron 을 재시작 합니다.
# systemctl restart neutron-server
external 네트워크에 서브넷을 생성합니다.
VM 에 할당할 외부 IP 대역 및 게이트웨이 정보를 입력합니다.
# openstack subnet create --network provider --allocation-pool start=115.68.142.66,end=115.68.142.94 --dns-nameserver 8.8.8.8 --gateway 115.68.142.65 --subnet-range 115.68.142.64/27 provider
+----------------------+--------------------------------------+
| Field | Value |
+----------------------+--------------------------------------+
| allocation_pools | 115.68.142.66-115.68.142.94 |
| cidr | 115.68.142.64/27 |
| created_at | 2023-07-17T06:12:12Z |
| description | |
| dns_nameservers | 8.8.8.8 |
| dns_publish_fixed_ip | None |
| enable_dhcp | True |
| gateway_ip | 115.68.142.65 |
| host_routes | |
| id | d2346f72-dd3b-4ef2-8065-0fd34d50177f |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | provider |
| network_id | b536c267-4a33-4068-a0da-4748a1cbfc97 |
| prefix_length | None |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2023-07-17T06:12:12Z |
+----------------------+--------------------------------------+
사용자 환경에 내부 네트워크 제공을 위해 사용자 환경을 로드 합니다.
테스트를 위해 admin 으로 VM 을 생성할 경우 바로 아래 명령은 넘어갑니다.
# source sysdocu-openrc
VM 끼리 내부 네트워크로 사용할 서브넷을 생성합니다.
# openstack network create selfservice
+---------------------------+--------------------------------------+
| Field | Value |
+---------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2023-07-14T01:35:56Z |
| description | |
| dns_domain | None |
| id | 30fbd00c-5968-40bf-a6e6-6e1b3307a232 |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | False |
| is_vlan_transparent | None |
| mtu | 1500 |
| name | selfservice |
| port_security_enabled | True |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| provider:network_type | vxlan |
| provider:physical_network | None |
| provider:segmentation_id | 477 |
| qos_policy_id | None |
| revision_number | 1 |
| router:external | Internal |
| segments | None |
| shared | False |
| status | ACTIVE |
| subnets | |
| tags | |
| updated_at | 2023-07-14T01:35:56Z |
+---------------------------+--------------------------------------+
# openstack subnet create --network selfservice --dns-nameserver 8.8.8.8 --gateway 172.16.1.1 --subnet-range 172.16.1.0/24 selfservice
+----------------------+--------------------------------------+
| Field | Value |
+----------------------+--------------------------------------+
| allocation_pools | 172.16.1.2-172.16.1.254 |
| cidr | 172.16.1.0/24 |
| created_at | 2023-07-14T01:36:07Z |
| description | |
| dns_nameservers | 8.8.8.8 |
| dns_publish_fixed_ip | None |
| enable_dhcp | True |
| gateway_ip | 172.16.1.1 |
| host_routes | |
| id | d577dadf-9d16-49ef-b495-69412745bc7b |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | selfservice |
| network_id | 30fbd00c-5968-40bf-a6e6-6e1b3307a232 |
| prefix_length | None |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2023-07-14T01:36:07Z |
+----------------------+--------------------------------------+
외부네트워크와 내부 네트워크를 연결하는 작업을 진행하기 위해 Router 를 생성합니다.
# openstack router create router
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2023-07-17T06:13:12Z |
| description | |
| distributed | False |
| external_gateway_info | null |
| flavor_id | None |
| ha | False |
| id | 12bb1577-1184-4aaf-a285-175579a0f13f |
| name | router |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| revision_number | 1 |
| routes | |
| status | ACTIVE |
| tags | |
| updated_at | 2023-07-17T06:13:12Z |
+-------------------------+--------------------------------------+
# openstack router add subnet router selfservice
# openstack router set router --external-gateway provider
연결을 확인합니다.
# source admin-openrc
# openstack router list
+--------------------------------------+--------+--------+-------+----------------------------------+-------------+-------+
| ID | Name | Status | State | Project | Distributed | HA |
+--------------------------------------+--------+--------+-------+----------------------------------+-------------+-------+
| 12bb1577-1184-4aaf-a285-175579a0f13f | router | ACTIVE | UP | 677861619c5445368a353ebeb0bcba2b | False | False |
+--------------------------------------+--------+--------+-------+----------------------------------+-------------+-------+
4. VM 생성
VM 초기 구성을 변경하기 위해 관련 패키지를 설치하고 파일을 생성합니다.
ubuntu 일반계정과 root 관리자 계정 두 가지 로그인 방법이 있으므로 상황에 맞게 사용하시면 됩니다.
# apt-get -y install cloud-init
# vi temp.sh
(root 계정으로 로그인 허용)
#cloud-config users: - name: root chpasswd: list: | root:12345678@#$% expire: False runcmd: - 'sed -i "s/^#PermitRootLogin .*/PermitRootLogin yes/" /etc/ssh/sshd_config' - 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' - 'systemctl restart sshd' |
(ubuntu 기본 계정으로 로그인 허용)
#cloud-config users: - name: ubuntu chpasswd: list: | ubuntu:12345678@#$% expire: False runcmd: - 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' - 'systemctl restart sshd' - 'sudo usermod -aG sudo ubuntu' - 'sed -i "s/\/ubuntu:\/bin\/sh/\/ubuntu:\/bin\/bash/" /etc/passwd' |
(root 패스워드를 설정하고, sudo 권한 가진 ubuntu 계정 생성)
#cloud-config users: - name: ubuntu chpasswd: list: | ubuntu:12345678@#$% expire: False runcmd: - 'sed -i "s/^PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config' - 'systemctl restart sshd' - 'useradd -m -d /home/ubuntu -s /bin/bash -G sudo ubuntu' - 'echo "ubuntu:12345678@#$%" | chpasswd' - 'echo "ubuntu ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers' |
Image 와 Flavor 를 이용해 VM 을 생성합니다.
VM 생성할때는 위에서 생성한 Flavor, Image, Key, (내부) Network 정보를 포함해야 합니다.
형식) openstack server create --flavor <FLAVOR_NAME> --image <IMAGE_NAME> --nic net-id <NETWORK_NAME> --user-data <INITIALIZE_FILE> <INSTANCE_NAME>
# openstack server create --flavor myflavor --image "CentOS7" --nic net-id=selfservice --user-data /root/temp.sh myinstance
+-------------------------------------+-------------------------------------------------+
| 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 | QSjCjKK3oiJi |
| config_drive | |
| created | 2023-07-14T05:16:28Z |
| flavor | myflavor (7e94605d-ace3-4980-94ad-fa49b36c4735) |
| hostId | |
| id | a23ff754-668f-4f9e-b517-376ae41ddc42 |
| image | CentOS7 (acbe118e-6881-4ecf-8447-868864150c81) |
| key_name | None |
| name | myinstance |
| progress | 0 |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| properties | |
| security_groups | name='default' |
| status | BUILD |
| updated | 2023-07-14T05:16:28Z |
| user_id | 7ffedad885e1490e9f5598081077f5a8 |
| volumes_attached | |
+-------------------------------------+-------------------------------------------------+
root@controller:~# openstack server list
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
| a23ff754-668f-4f9e-b517-376ae41ddc42 | myinstance | ACTIVE | selfservice=172.16.1.173 | CentOS7 | myflavor |
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
여기에 외부 IP 를 할당해줍니다.
아래 명령을 실행하면 provider 에 할당된 네트워크 범위에서 1개의 IP 를 자동 생성 시킵니다.
# openstack floating ip create provider
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| created_at | 2023-07-17T06:16:01Z |
| description | |
| dns_domain | None |
| dns_name | None |
| fixed_ip_address | None |
| floating_ip_address | 115.68.142.86 |
| floating_network_id | b536c267-4a33-4068-a0da-4748a1cbfc97 |
| id | dcc8088b-c577-41dd-ae40-d0bdd97865ed |
| name | 115.68.142.86 |
| port_details | None |
| port_id | None |
| project_id | 677861619c5445368a353ebeb0bcba2b |
| qos_policy_id | None |
| revision_number | 0 |
| router_id | None |
| status | DOWN |
| subnet_id | None |
| tags | [] |
| updated_at | 2023-07-17T06:16:01Z |
+---------------------+--------------------------------------+
생성된 외부 IP 를 확인합니다.
# openstack floating ip list
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
| ID | Floating IP Address | Fixed IP Address | Port | Floating Network | Project |
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
| dcc8088b-c577-41dd-ae40-d0bdd97865ed | 115.68.142.86 | None | None | b536c267-4a33-4068-a0da-4748a1cbfc97 | 677861619c5445368a353ebeb0bcba2b |
+--------------------------------------+---------------------+------------------+------+--------------------------------------+----------------------------------+
서버와 생생된 IP 를 연결해줍니다.
서버는 이름이나 ID 값 아무거나 넣어줘도 됩니다.
# openstack server add floating ip myinstance 115.68.142.86
IP 추가된것을 다시 확인합니다.
# openstack server list
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
| a23ff754-668f-4f9e-b517-376ae41ddc42 | myinstance | ACTIVE | selfservice=172.16.1.173, 115.68.142.86 | CentOS7 | myflavor |
+--------------------------------------+------------+--------+-----------------------------------------+---------+----------+
참고로 ssh 로도 접속이 가능하지만 네트워크가 안될 경우 NoVNC 를 통해서 접근하는 방법은 아래와 같습니다.
# openstack console url show myinstance
+-------+-------------------------------------------------------------------------------------------+
| Field | Value |
+-------+-------------------------------------------------------------------------------------------+
| type | novnc |
| url | http://controller:6080/vnc_auto.html?path=%3Ftoken%3Ddd017af1-27f8-4f49-a611-fe36d5d34c01 |
+-------+-------------------------------------------------------------------------------------------+
URL 중 'controller' 는 접속이 가능한 도메인 또는 IP 로 대체하여 웹브라우저로 접속하면 컨트롤 가능한 콘솔 화면이 출력됩니다.
'리눅스 > OpenStack' 카테고리의 다른 글
[Openstack] powering-off 상태의 VM 을 강제로 리부팅 하는 방법 (0) | 2023.07.27 |
---|---|
Openstack VM 생성시 에러 {'code': 400, ..., 'message': "Host is not mapped to any cell"} (0) | 2023.07.18 |
1. Openstack 환경 구성 (Victoria 버전) (0) | 2023.07.05 |
cinder 블록스토리지 상태값 강제 변경 (0) | 2018.06.18 |
provider 네트워크 대역 업데이트 및 추가 (0) | 2018.06.12 |