Cài đặt phần mềm cơ bản (Tất cả các node)
yum install -y vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel net-tools lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel bc systemd-devel bash-completion traceroute bridge-utils vsftpd
Quy hoạch Node
| Tên Host | Địa chỉ IP |
|---|---|
| openstack-controller1.ws.local | 172.31.7.101 |
| openstack-controller2.ws.local | 172.31.7.102 |
| openstack-mysql1.ws.local | 172.31.7.103 |
| openstack-mysql2.ws.local | 172.31.7.104 |
| openstack-haproxy1.ws.local | 172.31.7.105 |
| openstack-haproxy2.ws.local | 172.31.7.106 |
| openstack-node1.ws.local | 172.31.7.107 |
| openstack-node2.ws.local | 172.31.7.108 |
| openstack-node3.ws.local | 172.31.7.109 |
Keystone (Controller)
Thiết lập dữ liệu
# Cài đặt dịch vụ OpenStack cơ bản
yum install -y centos-release-openstack-train
yum install -y python-openstackclient openstack-selinux
# Cài đặt dịch vụ MariaDB
yum install -y mariadb mariadb-server
# Cấu hình tệp my.cnf.d/openstack.cnf
vim /etc/my.cnf.d/openstack.cnf
# Thêm các dòng sau vào phần [mysqld]
bind-address = 10.0.0.11
default-storage-engine = innodb
innodb_file_per_table = on
max_connections = 4096
collation-server = utf8_general_ci
character-set-server = utf8
# Khởi động và kích hoạt dịch vụ MariaDB
systemctl start mariadb; systemctl enable mariadb
# Khởi tạo bảo mật cho MariaDB
mysql_secure_installation
# Nhấn Enter cho mật khẩu root hiện tại (nếu có)
# Nhập 'n' cho câu hỏi "Set root password?"
# Nhập 'y' cho câu hỏi "Remove anonymous users?"
# Nhập 'n' cho câu hỏi "Disallow root login remotely?"
# Nhập 'y' cho câu hỏi "Remove test database and access to it?"
# Nhập 'y' cho câu hỏi "Reload privilege tables now?"
# Kết nối MariaDB
mysql -u root -p
# Nhập mật khẩu root bạn đã đặt (nếu có) hoặc nhấn Enter nếu không đặt
# Tạo cơ sở dữ liệu và người dùng cho Keystone
CREATE DATABASE keystone;
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'keystone123';
FLUSH PRIVILEGES;
EXIT;
# Cài đặt và cấu hình RabbitMQ
yum install -y rabbitmq-server
systemctl enable rabbitmq-server.service; systemctl start rabbitmq-server.service
# Tạo người dùng và cấp quyền cho OpenStack trong RabbitMQ
rabbitmqctl add_user openstack openstack123
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
# Kích hoạt plugin quản lý RabbitMQ
rabbitmq-plugins enable rabbitmq_management rabbitmq_management_agent
# Cài đặt và cấu hình Memcached
yum install -y memcached
# Cấu hình Memcached (tùy chỉnh theo nhu cầu)
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="1024"
OPTIONS="-l 0.0.0.0,::1"
# Lưu các tùy chọn vào file cấu hình nếu cần, hoặc đặt trực tiếp qua systemctl
systemctl enable memcached.service; systemctl start memcached.service
HA Proxy và Keepalived (HA Node)
# Cài đặt dịch vụ HAProxy và Keepalived
yum -y install haproxy keepalived
# Cấu hình Keepalived
vim /etc/keepalived/keepalived.conf
# Nội dung tệp cấu hình:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_iptables
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER # Thay đổi thành BACKUP trên node thứ hai
interface eth0
virtual_router_id 58
priority 100 # Giảm giá trị này trên node thứ hai (ví dụ: 90)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.31.7.248 dev eth0 label eth0:0
}
}
# Cấu hình HAProxy để đảo chiều các dịch vụ OpenStack
vim /etc/haproxy/haproxy.cfg
# Nội dung tệp cấu hình HAProxy (ví dụ cho MySQL, RabbitMQ, Memcached):
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
# Load balancer cho MySQL
listen openstack-mysql-3306
bind 172.31.7.248:3306
mode tcp
server mysql1 172.31.7.103:3306 check inter 3s fall 3 rise 5
server mysql2 172.31.7.104:3306 check inter 3s fall 3 rise 5
# Load balancer cho RabbitMQ
listen openstack-rabbitmq-5672
bind 172.31.7.248:5672
mode tcp
server rabbitmq1 172.31.7.103:5672 check inter 3s fall 3 rise 5
server rabbitmq2 172.31.7.104:5672 check inter 3s fall 3 rise 5
# Load balancer cho Memcached
listen openstack-memcache-11211
bind 172.31.7.248:11211
mode tcp
server memcache1 172.31.7.103:11211 check inter 3s fall 3 rise 5
server memcache2 172.31.7.104:11211 check inter 3s fall 3 rise 5
# Khởi động và kích hoạt dịch vụ HAProxy và Keepalived
systemctl restart haproxy keepalived
systemctl enable haproxy keepalived
Keystone (Controller - Cấu hình lại)
Trên các node controller, cấu hình Keystone.
# Cài đặt các gói cần thiết
yum -y install mariadb python2-PyMySQL python-memcached openstack-keystone httpd mod_wsgi
# Cấu hình Keystone
# Sử dụng tệp cấu hình từ controller1 hoặc cấu hình lại dựa trên tệp gốc
# Đảm bảo tệp /etc/keystone/keystone.conf được cấu hình chính xác:
# [database] connection = mysql+pymysql://keystone:keystone123@openstack-vip.ws.local/keystone
# [token] provider = fernet
# Cập nhật tệp hosts
vim /etc/hosts
172.31.7.248 openstack-vip.ws.local
# Đồng bộ hóa cơ sở dữ liệu (nếu chưa thực hiện trên controller1)
# su -s /bin/sh -c "keystone-manage db_sync" keystone
# Khởi tạo Fernet key (nếu chưa thực hiện)
# keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
# keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
# Khởi tạo dịch vụ Identity (chỉ cần chạy một lần trên một node controller chính)
# keystone-manage bootstrap --bootstrap-password admin --bootstrap-admin-url http://openstack-vip.ws.local:5000/v3 --bootstrap-internal-url http://openstack-vip.ws.local:5000/v3 --bootstrap-public-url http://openstack-vip.ws.local:5000/v3 --bootstrap-region-id RegionOne
# Cấu hình Apache HTTP Server
vim /etc/httpd/conf/httpd.conf
ServerName 172.31.7.101:80 # Thay đổi IP nếu cần
# Tạo liên kết tượng trưng cho tệp cấu hình WSGI của Keystone
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
# Khởi động và kích hoạt dịch vụ Apache
systemctl restart httpd; systemctl enable httpd
# Kiểm tra kết nối bằng curl
curl http://openstack-vip.ws.local:5000/v3
# Thiết lập biến môi trường cho tài khoản admin
# Tạo tệp admin.sh (hoặc tương tự)
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_PROJECT_NAME=admin
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_DOMAIN_NAME=Default
export OS_AUTH_URL=http://openstack-vip.ws.local:5000/v3
export OS_IDENTITY_API_VERSION=3
source admin.sh
# Tạo domain, project, user, role (nếu chưa thực hiện)
openstack domain create --description "An Example Domain" example
openstack project create --domain default --description "Service Project" service
openstack project create --domain default --description "Demo Project" myproject
openstack user create --domain default --password-prompt myuser
openstack role create myrole
openstack role add --project myproject --user myuser myrole
# Hủy biến môi trường
unset OS_AUTH_URL OS_PASSWORD
# Xác thực token cho admin
openstack --os-auth-url http://openstack-vip.ws.local:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name admin --os-username admin token issue
# Nhập mật khẩu admin
# Xác thực token cho myuser
openstack --os-auth-url http://openstack-vip.ws.local:5000/v3 --os-project-domain-name Default --os-user-domain-name Default --os-project-name myproject --os-username myuser token issue
# Nhập mật khẩu myuser
# Tạo tệp cấu hình openrc
# Tệp admin-openrc.sh
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_AUTH_URL=http://openstack-vip.ws.local:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
# Tệp demo-openrc.sh
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USER_DOMAIN_NAME=Default
export OS_PROJECT_NAME=myproject
export OS_USERNAME=myuser
export OS_PASSWORD=myuser
export OS_AUTH_URL=http://openstack-vip.ws.local:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
Glance (Controller)
Thiết lập chia sẻ dữ liệu (NFS)
# Cài đặt NFS utils
yum -y install nfs-utils
# Tạo thư mục lưu trữ ảnh
mkdir /data/glance -p
# Cấu hình chia sẻ NFS
vim /etc/exports
/data/glance *(rw,no_root_squash)
# Khởi động và kích hoạt dịch vụ NFS
systemctl start nfs; systemctl enable nfs
Cấu hình Glance trên Controller 1
# Tạo cơ sở dữ liệu và người dùng cho Glance
mysql -u root -p
CREATE DATABASE glance;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance123';
FLUSH PRIVILEGES;
EXIT;
# Tạo người dùng Glance trong Keystone
source admin-openrc.sh
openstack user create --domain default --password-prompt glance
# Đặt mật khẩu là 'glance'
# Gán quyền admin cho người dùng Glance trong project service
openstack role add --project service --user glance admin
# Tạo dịch vụ Glance
openstack service create --name glance --description "OpenStack Image" image
# Đăng ký API endpoint cho dịch vụ Glance
openstack endpoint create --region RegionOne image public http://openstack-vip.ws.local:9292
openstack endpoint create --region RegionOne image internal http://openstack-vip.ws.local:9292
openstack endpoint create --region RegionOne image admin http://openstack-vip.ws.local:9292
# Cài đặt Glance API
yum install openstack-glance
# Cấu hình tệp glance-api.conf
vim /etc/glance/glance-api.conf
[database]
connection = mysql+pymysql://glance:glance123@openstack-vip.ws.local/glance
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000
auth_url = http://openstack-vip.ws.local:5000
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = glance
password = glance
[paste_deploy]
flavor = keystone
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
# Đồng bộ hóa cơ sở dữ liệu Glance
su -s /bin/sh -c "glance-manage db_sync" glance
# Khởi động và kích hoạt dịch vụ Glance API
systemctl enable openstack-glance-api.service; systemctl start openstack-glance-api.service
# Cấu hình lưu trữ chia sẻ NFS
# Dừng dịch vụ Glance API trước khi mount
systemctl stop openstack-glance-api.service
mount -t nfs 172.31.7.103:/data/glance /var/lib/glance/images
# Cấu hình mount NFS vĩnh viễn
vim /etc/fstab
172.31.7.103:/data/glance /var/lib/glance/images nfs defaults,_netdev 0 0
# Thay đổi quyền sở hữu thư mục lưu trữ ảnh
# Lấy UID/GID của người dùng glance
id glance
# Thay thế 161:161 bằng UID:GID thực tế nếu khác
chown -R 161:161 /data/glance
# Mount tất cả các tệp trong fstab
mount -a
# Khởi động lại dịch vụ Glance API
systemctl start openstack-glance-api.service
# Kiểm tra hoạt động bằng cách tải lên một ảnh mẫu
wget http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img
openstack image create --name "cirros-0.4.0" --file cirros-0.4.0-x86_64-disk.img --disk-format qcow2 --container-format bare --visibility public
openstack image list
Placement (Controller)
Placement API là một dịch vụ độc lập kể từ phiên bản Stein, có nhiệm vụ thống kê tài nguyên của các node tính toán.
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Placement
mysql -u root -p
CREATE DATABASE placement;
GRANT ALL PRIVILEGES ON placement.* TO 'placement'@'%' IDENTIFIED BY 'placement123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình trên Controller 1
# Tạo người dùng Placement trong Keystone
source admin-openrc.sh
openstack user create --domain default --password-prompt placement
# Đặt mật khẩu là 'placement'
# Gán quyền admin cho người dùng Placement trong project service
openstack role add --project service --user placement admin
# Tạo dịch vụ Placement
openstack service create --name placement --description "Placement API" placement
# Đăng ký API endpoint cho dịch vụ Placement
openstack endpoint create --region RegionOne placement public http://openstack-vip.ws.local:8778
openstack endpoint create --region RegionOne placement internal http://openstack-vip.ws.local:8778
openstack endpoint create --region RegionOne placement admin http://openstack-vip.ws.local:8778
# Cài đặt Placement API
yum install openstack-placement-api
# Cấu hình tệp placement.conf
vim /etc/placement/placement.conf
[placement_database]
connection = mysql+pymysql://placement:placement123@openstack-vip.ws.local/placement
[api]
auth_strategy = keystone
[keystone_authtoken]
auth_url = http://openstack-vip.ws.local:5000/v3
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = placement
password = placement
# Đồng bộ hóa cơ sở dữ liệu Placement
su -s /bin/sh -c "placement-manage db sync" placement
# Khắc phục lỗi Apache cho Placement API
# Thêm cấu hình sau vào /etc/httpd/conf.d/00-placement-api.conf
vim /etc/httpd/conf.d/00-placement-api.conf
<Directory /usr/bin>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
# Khởi động lại dịch vụ Apache
systemctl restart httpd
# Kiểm tra trạng thái
placement-status upgrade check
Nova Controller
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Nova
mysql -u root -p
CREATE DATABASE nova_api;
CREATE DATABASE nova;
CREATE DATABASE nova_cell0;
GRANT ALL PRIVILEGES ON nova_api.* TO 'nova'@'%' IDENTIFIED BY 'nova123';
GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova123';
GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'%' IDENTIFIED BY 'nova123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình trên Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Nova trong Keystone
openstack user create --domain default --password-prompt nova
# Đặt mật khẩu là 'nova'
# Gán quyền admin cho người dùng Nova trong project service
openstack role add --project service --user nova admin
# Tạo dịch vụ Compute
openstack service create --name nova --description "OpenStack Compute" compute
# Đăng ký API endpoint cho dịch vụ Compute
openstack endpoint create --region RegionOne compute public http://openstack-vip.ws.local:8774/v2.1
openstack endpoint create --region RegionOne compute internal http://openstack-vip.ws.local:8774/v2.1
openstack endpoint create --region RegionOne compute admin http://openstack-vip.ws.local:8774/v2.1
# Kiểm tra đăng ký endpoint
openstack endpoint list
# Cài đặt các thành phần Nova Controller
yum install -y openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler
# Cấu hình tệp nova.conf
vim /etc/nova/nova.conf
[api_database]
connection = mysql+pymysql://nova:nova123@openstack-vip.ws.local/nova_api
[database]
connection = mysql+pymysql://nova:nova123@openstack-vip.ws.local/nova
[DEFAULT]
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local:5672/
enabled_apis = osapi_compute,metadata
[api]
auth_strategy = keystone
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000/
auth_url = http://openstack-vip.ws.local:5000/
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = nova
[DEFAULT]
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver
[vnc]
enabled = true
server_listen = 172.31.7.101
server_proxyclient_address = 172.31.7.101
[glance]
api_servers = http://openstack-vip.ws.local:9292
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://openstack-vip.ws.local:5000/v3
username = placement
password = placement
# Đồng bộ hóa cơ sở dữ liệu Nova API
su -s /bin/sh -c "nova-manage api_db sync" nova
# Đăng ký cell0
su -s /bin/sh -c "nova-manage cell_v2 map_cell0" nova
# Tạo cell1
su -s /bin/sh -c "nova-manage cell_v2 create_cell --name=cell1 --verbose" nova
# Đồng bộ hóa cơ sở dữ liệu Nova
su -s /bin/sh -c "nova-manage db sync" nova
# Kiểm tra danh sách cells
su -s /bin/sh -c "nova-manage cell_v2 list_cells" nova
# Kích hoạt và khởi động các dịch vụ Nova Controller
systemctl enable openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl start openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
Nova Compute (Node)
# Cài đặt nguồn yum và phần mềm cơ bản
yum install centos-release-openstack-train https://rdoproject.org/repos/rdo-release.rpm
yum install -y python-openstackclient openstack-selinux
# Cài đặt Nova Compute
yum install -y openstack-nova-compute
# Cấu hình tệp nova.conf
vim /etc/nova/nova.conf
[DEFAULT]
enabled_apis = osapi_compute,metadata
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
[api]
auth_strategy = keystone
[keystone_authtoken]
auth_url = http://openstack-vip.ws.local:5000/v3
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = Default
user_domain_name = Default
project_name = service
username = nova
password = nova
[DEFAULT]
use_neutron = true
firewall_driver = nova.virt.firewall.NoopFirewallDriver
[vnc]
enabled = true
server_listen = 0.0.0.0
server_proxyclient_address = 172.31.7.107 # IP của node compute này
novncproxy_base_url = http://openstack-vip.ws.local:6080/vnc_auto.html
[glance]
api_servers = http://openstack-vip.ws.local:9292
[oslo_concurrency]
lock_path = /var/lib/nova/tmp
[placement]
region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://openstack-vip.ws.local:5000/v3
username = placement
password = placement
# Kiểm tra hỗ trợ ảo hóa CPU
egrep -c '(vmx|svm)' /proc/cpuinfo
# Nếu kết quả là 0, cần thêm cấu hình sau vào nova.conf
# [libvirt]
# virt_type = qemu
# Cấu hình phân giải tên miền
vim /etc/hosts
172.31.7.248 openstack-vip.ws.local
# Khởi động và kích hoạt dịch vụ libvirtd và nova-compute
systemctl enable libvirtd.service openstack-nova-compute.service
systemctl start libvirtd.service openstack-nova-compute.service
# Trên node Controller: Xác minh node compute đã tham gia
source admin-openrc.sh
openstack compute service list --service nova-compute
# Trên node Controller: Phát hiện host
su -s /bin/sh -c "nova-manage cell_v2 discover_hosts --verbose" nova
# Để tự động phát hiện, cấu hình trong /etc/nova/nova.conf:
# [scheduler]
# discover_hosts_in_cells_interval = 300
# Khởi động lại các dịch vụ Controller
systemctl restart openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
# Kiểm tra trạng thái dịch vụ Nova
openstack compute service list
openstack catalog list
nova-status upgrade check
Neutron Controller
Neutron cung cấp dịch vụ mạng cho OpenStack. Có hai loại mạng chính: mạng Provider (cầu nối) và mạng Self-service.
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Neutron
mysql -u root -p
CREATE DATABASE neutron;
GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'neutron123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Neutron trong Keystone
openstack user create --domain default --password-prompt neutron
# Đặt mật khẩu là 'neutron'
# Gán quyền admin cho người dùng Neutron trong project service
openstack role add --project service --user neutron admin
# Tạo dịch vụ Network
openstack service create --name neutron --description "OpenStack Networking" network
# Đăng ký API endpoint cho dịch vụ Neutron
openstack endpoint create --region RegionOne network public http://openstack-vip.ws.local:9696
openstack endpoint create --region RegionOne network internal http://openstack-vip.ws.local:9696
openstack endpoint create --region RegionOne network admin http://openstack-vip.ws.local:9696
# Cài đặt các thành phần Neutron Controller
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables
# Cấu hình tệp neutron.conf
vim /etc/neutron/neutron.conf
[database]
connection = mysql+pymysql://neutron:neutron123@openstack-vip.ws.local/neutron
[DEFAULT]
core_plugin = ml2
service_plugins = router # Kích hoạt plugin router cho mạng self-service
allow_overlapping_ips = true # Cho phép IP trùng lặp giữa các tenant
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000
auth_url = http://openstack-vip.ws.local:5000
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron
[DEFAULT]
notify_nova_on_port_status_changes = true
notify_nova_on_port_data_changes = true
[nova]
auth_url = http://openstack-vip.ws.local:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = nova
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
# Cấu hình tệp ml2_conf.ini
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan # Sử dụng VXLAN cho mạng tenant
mechanism_drivers = linuxbridge,l2population # Sử dụng Linux Bridge và L2 Population
extension_drivers = port_security
[ml2_type_flat]
flat_networks = external # Định nghĩa mạng external
[ml2_type_vxlan]
vni_ranges = 1:1000
[securitygroup]
enable_security_group = true
enable_ipset = true
# Cấu hình tệp linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1 # Ánh xạ mạng vật lý với giao diện mạng
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.101 # Địa chỉ IP của node controller này
l2_population = true
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình tệp l3_agent.ini
vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = linuxbridge
# Cấu hình DHCP agent
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
# Cấu hình Metadata agent
vim /etc/neutron/metadata_agent.ini
[DEFAULT]
nova_metadata_host = openstack-vip.ws.local
metadata_proxy_shared_secret = xier123
# Cấu hình Nova để sử dụng Neutron
vim /etc/nova/nova.conf
[neutron]
auth_url = http://openstack-vip.ws.local:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
service_metadata_proxy = true
metadata_proxy_shared_secret = xier123
# Cấu hình kernel cho bridging
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
modprobe br_netfilter
sysctl -p
# Đồng bộ hóa cơ sở dữ liệu Neutron
# Đảm bảo liên kết tượng trưng plugin.ini
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
# Khởi động và kích hoạt các dịch vụ Neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Khởi động lại dịch vụ Nova API
systemctl restart openstack-nova-api.service
# Kiểm tra agent Neutron
neutron agent-list
Neutron Compute (Node)
# Cài đặt các thành phần Neutron Agent
yum install -y openstack-neutron-linuxbridge ebtables ipset
# Cấu hình tệp neutron.conf
vim /etc/neutron/neutron.conf
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000
auth_url = http://openstack-vip.ws.local:5000
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = neutron
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
# Cấu hình tệp linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.107 # Địa chỉ IP của node compute này
l2_population = true
[securitygroup]
enable_security_group = false # Tắt security group trên agent để tránh xung đột
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình kernel cho bridging
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Cấu hình Nova để giao tiếp với Neutron
vim /etc/nova/nova.conf
[neutron]
auth_url = http://openstack-vip.ws.local:5000
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
# Khởi động và kích hoạt dịch vụ Neutron Agent
systemctl enable neutron-linuxbridge-agent.service
systemctl restart neutron-linuxbridge-agent.service
# Khởi động lại dịch vụ Nova Compute để áp dụng cấu hình Neutron
systemctl restart openstack-nova-compute.service
Tạo một Instance (VM)
# Tạo cặp khóa SSH
ssh-keygen -q -N "" -t rsa
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
# Tạo mạng External
openstack network create --share --external --provider-physical-network external --provider-network-type flat external-net
# Tạo Subnet cho mạng External
openstack subnet create --network external-net --allocation-pool start=172.31.7.50,end=172.31.7.100 --dns-nameserver 223.6.6.6 --gateway 172.31.7.254 --subnet-range 172.31.7.0/24 external-sub
# Tạo Flavor (kiểu máy ảo)
openstack flavor create --id 0 --vcpus 1 --ram 64 --disk 1 m1.nano
# Tạo Security Group Rule cho phép ping (ICMP)
openstack security group rule create --proto icmp default
# Tạo Security Group Rule cho phép SSH (TCP port 22)
openstack security group rule create --proto tcp --dst-port 22 default
# Lấy ID của mạng external
PROVIDER_NET_ID=$(openstack network show external-net -f value -c id)
# Tạo Instance (VM)
openstack server create --flavor m1.nano --image cirros --nic net-id=$PROVIDER_NET_ID --security-group default --key-name mykey train-mv1
# Khắc phục lỗi VM không khởi động được hoặc không có IP
# Kiểm tra loại ảo hóa được host hỗ trợ
virsh capabilities | grep "hypervisor"
# Sửa đổi cấu hình Nova nếu cần thiết (ví dụ: nếu virt_type không phù hợp)
# vim /etc/nova/nova.conf
# [libvirt]
# hw_machine_type = x86_64=pc-i440fx-rhel7.2.0 # Ví dụ, thay đổi tùy theo hệ thống
# cpu_mode = host-passthrough
# Khởi động lại dịch vụ Nova Compute
# systemctl restart openstack-nova-compute.service
# Kiểm tra trạng thái VM
openstack server list
openstack console url show train-mv1 # Để truy cập console của VM
Dashboard (Controller)
# Cài đặt OpenStack Dashboard
yum install openstack-dashboard -y
# Cấu hình tệp local_settings
vim /etc/openstack-dashboard/local_settings
OPENSTACK_HOST = "172.31.7.101" # IP của controller hoặc VIP
ALLOWED_HOSTS = ['172.31.7.101', 'openstack-vip.ws.local'] # Danh sách IP/domain cho phép truy cập
# Cấu hình Session và Cache
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'
WEBROOT = '/dashboard' # Thay đổi nếu bạn muốn truy cập qua một đường dẫn con
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': 'openstack-vip.ws.local:11211',
}
}
# Cấu hình Keystone API Version
OPENSTACK_KEYSTONE_URL = "http://%s:5000/v3" % OPENSTACK_HOST
OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT = True
OPENSTACK_KEYSTONE_DEFAULT_DOMAIN = "Default"
OPENSTACK_KEYSTONE_DEFAULT_ROLE = "user"
# Cấu hình các API Version
OPENSTACK_API_VERSIONS = {
"identity": 3,
"image": 2,
"volume": 3,
}
# Tắt các tính năng Neutron không dùng cho mạng Provider
OPENSTACK_NEUTRON_NETWORK = {
'enable_router': False,
'enable_quotas': False,
'enable_distributed_router': False,
'enable_ha_router': False,
'enable_lb': False,
'enable_firewall': False,
'enable_vpn': False,
'enable_fip_topology_check': False,
}
TIME_ZONE = "Asia/" # Đặt múi giờ phù hợp
# Cấu hình Apache cho Dashboard
vim /etc/httpd/conf.d/openstack-dashboard.conf
WSGIApplicationGroup %{GLOBAL}
# Khởi động lại dịch vụ Apache
systemctl restart httpd.service
# Kiểm tra Memcached
telnet 172.31.7.248 11211
stats items
stats cachedump ID 0
get <key>
Thêm Compute Node (node2, node3)
Sử dụng script để tự động hóa quá trình thêm node mới.
Chuẩn bị
- Tạo một thư mục cho script, ví dụ:
openstack-compute. - Chuẩn bị các tệp cấu hình nén (
nova-computer.tar.gz,neutron-compute.tar.gz) từ một node đã cấu hình. - Chuẩn bị các tệp cấu hình kernel (
sysctl.conf) và giới hạn tài nguyên (limits.conf). - Chuẩn bị tệp
profileđể cấu hình lịch sử lệnh.
Script cài đặt (openstack-compute-install.sh)
#!/bin/bash
echo "Đang thay thế nguồn yum..."
# Cập nhật cấu hình yum nếu cần
sleep 3
echo "Thay thế nguồn yum hoàn tất."
echo "Đang đồng bộ thời gian..."
/usr/sbin/ntpdate time1.aliyun.com && hwclock -w
echo "Đồng bộ thời gian hoàn tất. Thời gian hiện tại: $(date '+%Y-%m-%d %H:%M:%S')"
sleep 1
echo "Đang tối ưu hóa hệ thống (tham số kernel, giới hạn tài nguyên, định dạng lịch sử lệnh)..."
sleep 1
cp limits.conf /etc/security/limits.conf
cp sysctl.conf /etc/sysctl.conf
echo "export HISTTIMEFORMAT="%F %T `whoami`"" >> /etc/profile
sleep 1
echo "172.31.7.248 openstack-vip.ws.local" >> /etc/hosts
sleep 1
echo "Tối ưu hóa tham số hệ thống hoàn tất."
sleep 1
# Cài đặt các gói OpenStack cơ bản
yum install -y centos-release-openstack-train python-openstackclient openstack-selinux
# Cài đặt Nova Compute
echo "Đang cài đặt Nova..."
sleep 1
yum install -y openstack-nova-compute
echo "Cài đặt Nova hoàn tất. Đang thay thế cấu hình..."
sleep 1
tar xvf nova-computer.tar.gz -C /etc/nova
NODE_IP=$(ifconfig eth0 | grep -w inet | awk '{print $2}')
echo "Địa chỉ IP của node compute hiện tại là $NODE_IP. Đang cập nhật nova.conf..."
sleep 1
sed -i "s/server_proxyclient_address = 172.31.7.107/server_proxyclient_address = $NODE_IP/g" /etc/nova/nova.conf
systemctl enable libvirtd.service openstack-nova-compute.service; systemctl start libvirtd.service openstack-nova-compute.service
# Cài đặt Neutron Linux Bridge Agent
echo "Đang cài đặt Neutron..."
sleep 1
yum install -y openstack-neutron-linuxbridge ebtables ipset
echo "Cài đặt Neutron hoàn tất. Đang thay thế cấu hình..."
sleep 1
tar xvf neutron-compute.tar.gz -C /etc/neutron
# Sao chép tệp agent nếu cần thiết
# cp linuxbridge_neutron_agent.py /usr/lib/python2.7/site-packages/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py
systemctl enable neutron-linuxbridge-agent.service; systemctl start neutron-linuxbridge-agent.service
echo "Cài đặt và cấu hình Nova/Neutron cho node compute hoàn tất. Hệ thống sẽ khởi động lại sau 1 phút để xác minh dịch vụ."
sleep 3
shutdown -r +1 "Hệ thống sẽ khởi động lại sau 1 phút. Vui lòng kiểm tra log của Nova và Neutron sau khi khởi động lại."
Đóng gói và triển khai
- Đóng gói script và các tệp hỗ trợ:
tar zcvf openstack-compute-install.tar.gz openstack-compute/ - Trên node Controller, xóa đăng ký agent Neutron và Nova cũ:
- Copy tệp đóng gói lên các node compute mới và giải nén, chạy script.
- Sau khi node khởi động lại, xác minh trên Controller xem Nova và Neutron đã đăng ký thành công chưa.
# Xóa agent Neutron
neutron agent-list
neutron agent-delete
# Xóa dịch vụ Nova Compute
nova service-list
nova service-delete
Controller HA (Controller 2)
Thực hiện cấu hình HA cho các dịch vụ chính trên Controller 2.
Keystone
# Cài đặt các gói cần thiết
yum install -y centos-release-openstack-train python-openstackclient openstack-selinux mariadb python2-PyMySQL python-memcached openstack-keystone httpd mod_wsgi
# Sao chép cấu hình Keystone từ Controller 1
# Trên Controller 1:
# cd /etc/keystone/
# tar zcvf keystone-controller1.tar.gz ./*
# scp keystone-controller1.tar.gz 172.31.7.102:/etc/keystone/
# Trên Controller 2:
# cd /etc/keystone/
# tar zxvf keystone-controller1.tar.gz
# Cập nhật tệp hosts
vim /etc/hosts
172.31.7.248 openstack-vip.ws.local
# Cấu hình Apache
vim /etc/httpd/conf/httpd.conf
ServerName 172.31.7.102:80 # Thay đổi IP
# Tạo liên kết tượng trưng và khởi động Apache
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
systemctl enable httpd.service; systemctl start httpd.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy để bao gồm Controller 2
vim /etc/haproxy/haproxy.cfg
# Thêm server cho Controller 2 vào các section tương ứng (ví dụ: keystone, glance, placement, nova, neutron, dashboard)
listen openstack-keystone-5000
bind 172.31.7.248:5000
mode tcp
server controller1 172.31.7.101:5000 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:5000 check inter 3s fall 3 rise 5
# Lặp lại cho các dịch vụ khác
systemctl restart haproxy
Glance
# Cài đặt Glance API
yum install -y openstack-glance
# Tạo thư mục mount NFS
mkdir /var/lib/glance/images
chown -R glance.glance /var/lib/glance/images
# Cấu hình NFS mount vĩnh viễn
vim /etc/fstab
172.31.7.105:/data/glance /var/lib/glance/images nfs defaults,_netdev 0 0
# Sao chép cấu hình Glance từ Controller 1
# Trên Controller 1:
# cd /etc/glance
# tar zcvf glance-controller1.tar.gz ./*
# scp glance-controller1.tar.gz 172.31.7.102:/etc/glance/
# Trên Controller 2:
# cd /etc/glance
# tar zxvf glance-controller1.tar.gz
# Khởi động và kích hoạt dịch vụ Glance API
systemctl enable openstack-glance-api.service; systemctl start openstack-glance-api.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Glance
vim /etc/haproxy/haproxy.cfg
listen openstack-glance-9292
bind 172.31.7.248:9292
mode tcp
server controller1 172.31.7.101:9292 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:9292 check inter 3s fall 3 rise 5
systemctl restart haproxy
Placement
# Cài đặt Placement API
yum install -y openstack-placement-api
# Sao chép cấu hình Placement từ Controller 1
# Trên Controller 1:
# cd /etc/placement/
# tar zcvf placement-controller1.tar.gz ./*
# scp placement-controller1.tar.gz 172.31.7.102:/etc/placement/
# Trên Controller 2:
# cd /etc/placement/
# tar zxvf placement-controller1.tar.gz
# Khắc phục lỗi Apache cho Placement API (tương tự Controller 1)
vim /etc/httpd/conf.d/00-placement-api.conf
# Thêm cấu hình <Directory /usr/bin> ...
# Khởi động lại dịch vụ Apache
systemctl restart httpd
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Placement
vim /etc/haproxy/haproxy.cfg
listen openstack-placement-8778 # Hoặc cổng tương ứng
bind 172.31.7.248:8778
mode tcp
server controller1 172.31.7.101:8778 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:8778 check inter 3s fall 3 rise 5
systemctl restart haproxy
# Kiểm tra trạng thái
placement-status upgrade check
Nova
# Cài đặt các thành phần Nova Controller
yum install -y openstack-nova-api openstack-nova-conductor openstack-nova-novncproxy openstack-nova-scheduler
# Sao chép cấu hình Nova từ Controller 1
# Trên Controller 1:
# cd /etc/nova/
# tar zcvf nova-controller.tar.gz ./*
# scp nova-controller.tar.gz 172.31.7.102:/etc/nova/
# Trên Controller 2:
# cd /etc/nova/
# tar zxvf nova-controller.tar.gz
# Cập nhật cấu hình IP trong nova.conf
vim /etc/nova/nova.conf
server_listen = 172.31.7.102
server_proxyclient_address = 172.31.7.102
# Khởi động và kích hoạt các dịch vụ Nova Controller
systemctl enable openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
systemctl start openstack-nova-api.service openstack-nova-scheduler.service openstack-nova-conductor.service openstack-nova-novncproxy.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Nova API và VNC Proxy
vim /etc/haproxy/haproxy.cfg
listen openstack-nova-8774
bind 172.31.7.248:8774
mode tcp
server controller1 172.31.7.101:8774 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:8774 check inter 3s fall 3 rise 5
listen openstack-nova-novncproxy-6080
bind 172.31.7.248:6080
mode tcp
server controller1 172.31.7.101:6080 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:6080 check inter 3s fall 3 rise 5
systemctl restart haproxy
# Xác minh dịch vụ Nova trên Controller 2
source admin-openrc.sh
nova service-list
Neutron
# Cài đặt các thành phần Neutron Controller
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables
# Sao chép cấu hình Neutron từ Controller 1
# Trên Controller 1:
# cd /etc/neutron
# tar zcvf neutron-controller1.tar.gz ./
# scp neutron-controller1.tar.gz 172.31.7.102:/etc/neutron/
# Trên Controller 2:
# cd /etc/neutron
# tar zxvf neutron-controller1.tar.gz
# Cập nhật cấu hình kernel cho bridging
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Khởi động và kích hoạt các dịch vụ Neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Neutron
vim /etc/haproxy/haproxy.cfg
listen openstack-neutron-9696
bind 172.31.7.248:9696
mode tcp
server controller1 172.31.7.101:9696 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:9696 check inter 3s fall 3 rise 5
systemctl reload haproxy
# Kiểm tra agent Neutron
neutron agent-list
Dashboard
# Cài đặt OpenStack Dashboard
yum install -y openstack-dashboard
# Sao chép cấu hình Dashboard từ Controller 1
# Trên Controller 1:
# cd /etc/openstack-dashboard/
# tar zcvf openstack-dashboard-controller1.tar.gz ./
# scp openstack-dashboard-controller1.tar.gz 172.31.7.102:/etc/openstack-dashboard/
# Trên Controller 2:
# cd /etc/openstack-dashboard/
# tar zxvf openstack-dashboard-controller1.tar.gz
# Cấu hình tệp local_settings
vim /etc/openstack-dashboard/local_settings
OPENSTACK_HOST = '172.31.7.102' # Thay đổi IP
ALLOWED_HOSTS = [ '172.31.7.102', 'openstack-vip.ws.local' ] # Thêm IP của Controller 2
# Khởi động lại dịch vụ Apache
systemctl restart httpd.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Dashboard
vim /etc/haproxy/haproxy.cfg
listen openstack-dashboard-80
bind 172.31.7.248:80
mode tcp
server controller1 172.31.7.101:80 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:80 check inter 3s fall 3 rise 5
Tối ưu hóa OpenStack
Cấu hình tự khởi động VM
Trên các node Compute, trong tệp /etc/nova/nova.conf, thêm hoặc sửa đổi:
[DEFAULT]
resume_guests_state_on_host_boot=true
Cấu hình tỷ lệ cấp phát tài nguyên (Overcommit)
Trong /etc/nova/nova.conf trên các node Compute:
[cpu_allocation_ratio]
# Ví dụ: Cho phép sử dụng 16 lần CPU vật lý
16
[ram_allocation_ratio]
# Ví dụ: Cho phép sử dụng 1.5 lần bộ nhớ vật lý
1.5
[disk_allocation_ratio]
# KHÔNG khuyến khích đặt giá trị lớn hơn 1.0, có thể gây mất dữ liệu.
1.0
# Dự trữ dung lượng đĩa cho hệ thống
[DEFAULT]
reserved_host_disk_mb=20480 # 20GB
# Dự trữ bộ nhớ cho hệ thống
[DEFAULT]
reserved_host_memory_mb=4096 # 4GB
Cho phép thay đổi loại Instance/di chuyển Instance
Trên các node Compute, trong tệp /etc/nova/nova.conf:
[DEFAULT]
allow_resize_to_same_host=true
Để thực hiện di chuyển hoặc thay đổi loại Instance:
- Đảm bảo người dùng
novacó thể SSH không cần mật khẩu giữa các node Compute và Controller. - Cấu hình quyền truy cập SSH cho người dùng
novatrên tất cả các node. - Thực hiện lệnh
openstack server resize ...hoặcopenstack server migrate ...từ Controller.
Cinder (Lưu trữ Block)
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Cinder
mysql -u root -p
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller (1 và 2)
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Cinder
openstack user create --domain default --password-prompt cinder
# Đặt mật khẩu là 'cinder'
# Gán quyền admin cho người dùng Cinder trong project service
openstack role add --project service --user cinder admin
# Tạo dịch vụ Block Storage (volumev2, volumev3)
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
# Đăng ký API endpoint cho Cinder
openstack endpoint create --region RegionOne volumev2 public http://openstack-vip.ws.local:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev2 internal http://openstack-vip.ws.local:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev2 admin http://openstack-vip.ws.local:8776/v2/%(project_id)s
openstack endpoint create --region RegionOne volumev3 public http://openstack-vip.ws.local:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 internal http://openstack-vip.ws.local:8776/v3/%(project_id)s
openstack endpoint create --region RegionOne volumev3 admin http://openstack-vip.ws.local:8776/v3/%(project_id)s
# Cài đặt Cinder API và Scheduler
yum install openstack-cinder -y
# Cấu hình tệp cinder.conf
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:cinder123@openstack-vip.ws.local/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
my_ip = 10.0.0.11 # Hoặc IP của Controller
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000
auth_url = http://openstack-vip.ws.local:5000
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = cinder
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Đồng bộ hóa cơ sở dữ liệu Cinder
su -s /bin/sh -c "cinder-manage db sync" cinder
# Cấu hình Nova để nhận biết Cinder
vim /etc/nova/nova.conf
[cinder]
os_region_name = RegionOne
# Khởi động và kích hoạt dịch vụ Cinder
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
# Trên HA Proxy Node 1: Cập nhật cấu hình HAProxy cho Cinder
vim /etc/haproxy/haproxy.cfg
listen openstack-cinder-8776
bind 172.31.7.248:8776
mode tcp
server controller1 172.31.7.101:8776 check inter 3s fall 3 rise 5
server controller2 172.31.7.102:8776 check inter 3s fall 3 rise 5
systemctl reload haproxy
# Kiểm tra dịch vụ Cinder
openstack volume service list
Cấu hình Cinder với LVM trên Compute Node
# Trên Compute Node (ví dụ: node1, node2, node3):
# Thêm một ổ đĩa vật lý mới (ví dụ: /dev/sdb) cho lưu trữ Cinder.
# Quét và nhận diện ổ đĩa mới
for host in /sys/class/scsi_host/host*; do echo "- - -" > $host/scan; done
# Cài đặt LVM2
yum install lvm2 device-mapper-persistent-data -y
systemctl enable lvm2-lvmetad.service; systemctl start lvm2-lvmetad.service
# Tạo Physical Volume (PV) trên ổ đĩa mới
pvcreate /dev/sdb
# Tạo Volume Group (VG) cho Cinder
vgcreate cinder-volumes /dev/sdb
# Cấu hình LVM filter để chỉ cho phép Cinder sử dụng VG này
vim /etc/lvm/lvm.conf
devices {
filter = [ "a/sdb/", "r/.*/"] # Chỉ cho phép /dev/sdb, loại trừ các ổ đĩa khác
}
systemctl restart lvm2-lvmetad.service
# Cài đặt Cinder Volume và Target
yum install openstack-cinder targetcli python-keystone -y
# Cấu hình tệp cinder.conf trên Compute Node
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:cinder123@openstack-vip.ws.local/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
my_ip = 172.31.7.107 # IP của Compute Node này
glance_api_servers = http://openstack-vip.ws.local:9292
[keystone_authtoken]
www_authenticate_uri = http://openstack-vip.ws.local:5000
auth_url = http://openstack-vip.ws.local:5000
memcached_servers = openstack-vip.ws.local:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = cinder
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
[DEFAULT]
enabled_backends = lvm
# volume_backend_name = Openstack-lvm # Có thể đặt tên backend nếu cần
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Khởi động và kích hoạt dịch vụ Cinder Volume và Target
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
# Trên Controller Node: Tạo Volume Type và liên kết với backend LVM
openstack volume type create lvm
openstack volume type set lvm capabilities=volume_backend_name=Openstack-lvm
Cấu hình Cinder với NFS trên Compute Node
Yêu cầu NFS server đã được cấu hình và chia sẻ thư mục.
# Trên NFS Server (ví dụ: mysql1):
# Tạo thư mục chia sẻ
mkdir /data/cinder
# Cấu hình chia sẻ NFS
vim /etc/exports
/data/cinder *(rw,no_root_squash)
systemctl start nfs
# Trên Controller Node (1 và 2):
# Cấu hình cinder.conf để sử dụng NFS
vim /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = nfs # Hoặc lvm,nfs nếu có cả hai
[nfs]
volume_backend_name = openstack-nfs
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs_shares
nfs_mount_point_base = $state_path/mnt
# Tạo tệp cấu hình nfs_shares
vim /etc/cinder/nfs_shares
172.31.7.105:/data/cinder
# Đảm bảo quyền sở hữu đúng cho tệp nfs_shares
chown root.cinder /etc/cinder/nfs_shares
# Khởi động lại các dịch vụ Cinder Controller
systemctl restart openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
# Trên Controller Node: Tạo Volume Type NFS
openstack volume type create nfs
openstack volume type set nfs capabilities=volume_backend_name=openstack-nfs
# Trên Compute Node: Cấu hình cinder.conf để nhận diện Volume Backend NFS (nếu cần)
# Thông thường, Cinder Volume service trên Controller sẽ quản lý backend.
# Nếu bạn có Cinder Volume service trên Compute node, cần cấu hình tương ứng.
Mạng Self-Service
Cho phép người dùng tự tạo mạng ảo.
Cấu hình Controller
# Cài đặt Neutron và các plugin cần thiết
yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y
# Cấu hình neutron.conf
vim /etc/neutron/neutron.conf
[database]
connection = mysql+pymysql://neutron:neutron123@openstack-vip.ws.local/neutron
[DEFAULT]
core_plugin = ml2
service_plugins = router # Kích hoạt router plugin
allow_overlapping_ips = true
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
[keystone_authtoken]
# ... (cấu hình keystone_authtoken như các dịch vụ khác) ...
[nova]
# ... (cấu hình nova section như các dịch vụ khác) ...
[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
# Cấu hình ml2_conf.ini
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan # Sử dụng VXLAN cho mạng tenant
mechanism_drivers = linuxbridge,l2population
extension_drivers = port_security
[ml2_type_flat]
flat_networks = external
[ml2_type_vxlan]
vni_ranges = 1:1000
[securitygroup]
enable_security_group = true
enable_ipset = true
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1 # Ánh xạ mạng vật lý
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.101 # IP của node Controller
l2_population = true
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình l3_agent.ini
vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = linuxbridge
# Cấu hình DHCP agent
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
modprobe br_netfilter
sysctl -p
# Đồng bộ hóa cơ sở dữ liệu Neutron
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
# Khởi động và kích hoạt các dịch vụ Neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Cấu hình Dashboard để hỗ trợ Router
vim /etc/openstack-dashboard/local_settings
# Thêm hoặc sửa đổi mục OPENSTACK_NEUTRON_NETWORK
OPENSTACK_NEUTRON_NETWORK = {
# ... các cấu hình khác ...
'enable_router': True,
'enable_quotas': True,
'enable_distributed_router': True,
'enable_ha_router': True,
'enable_lb': True,
'enable_firewall': True,
'enable_vpn': True,
'enable_fip_topology_check': True,
}
systemctl restart httpd
# Kiểm tra agent Neutron
neutron agent-list
Cấu hình Compute Node
# Cài đặt Neutron Agent
yum install -y openstack-neutron-linuxbridge ebtables ipset
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.107 # IP của node Compute này
l2_population = true
[securitygroup]
enable_security_group = false # Tắt trên agent để tránh xung đột
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Khởi động và kích hoạt dịch vụ Neutron Agent
systemctl enable neutron-linuxbridge-agent.service
systemctl restart neutron-linuxbridge-agent.service
# Khởi động lại dịch vụ Nova Compute
systemctl restart openstack-nova-compute.service
Sau khi cấu hình, người dùng có thể tạo mạng, subnet, router và cổng ảo từ Dashboard hoặc CLI.
Tối ưu hóa cấu hình OpenStack
Tỷ lệ cấp phát tài nguyên (Overcommit)
Trong /etc/nova/nova.conf trên các node Compute:
[cpu_allocation_ratio]
# Cho phép sử dụng 16 lần CPU vật lý
16
[ram_allocation_ratio]
# Cho phép sử dụng 1.5 lần bộ nhớ vật lý
1.5
# KHÔNG khuyến khích đặt disk_allocation_ratio > 1.0
# [disk_allocation_ratio]
# 1.0
# Dự trữ tài nguyên cho hệ điều hành host
[DEFAULT]
reserved_host_disk_mb=20480 # 20GB
reserved_host_memory_mb=4096 # 4GB
Cho phép thay đổi loại Instance/Di chuyển Instance
Trong /etc/nova/nova.conf trên các node Compute:
[DEFAULT]
allow_resize_to_same_host=true
Thực hiện các lệnh openstack server resize hoặc openstack server migrate từ Controller.
OpenStack Instance Type Adjustment & Cross-Host Migration
Quá trình này tương tự như thay đổi loại Instance.
- Đảm bảo người dùng
novacó thể SSH không cần mật khẩu giữa các node Compute và Controller. - Cài đặt
acpidtrên các node Compute nếu cần thiết để quản lý trạng thái VM (ví dụ: shutdown, reboot). - Thực hiện lệnh di chuyển hoặc thay đổi loại từ Controller.
Cinder (Tạo Volume và Snapshot)
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Cinder
mysql -u root -p
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Cinder và các dịch vụ liên quan (như đã mô tả ở phần Cinder HA)
# ...
# Cấu hình cinder.conf với backend LVM hoặc NFS
# Xem lại phần Cinder HA và Cinder NFS để cấu hình chi tiết.
# Đồng bộ hóa cơ sở dữ liệu
su -s /bin/sh -c "cinder-manage db sync" cinder
# Khởi động và kích hoạt dịch vụ Cinder
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
# Trên Compute Node: Cấu hình backend lưu trữ (LVM hoặc NFS)
# ... (xem lại phần Cinder HA và Cinder NFS) ...
# Kiểm tra dịch vụ Cinder
openstack volume service list
# Tạo Volume Type (nếu chưa có)
openstack volume type create lvm
openstack volume type set lvm capabilities=volume_backend_name=Openstack-lvm
openstack volume type create nfs
openstack volume type set nfs capabilities=volume_backend_name=openstack-nfs
# Tạo Volume
openstack volume create --size 10 --type lvm my-lvm-volume
openstack volume create --size 5 --type nfs my-nfs-volume
# Tạo Snapshot
openstack volume snapshot create --volume my-lvm-volume my-snapshot
Mạng Self-Service
Cho phép người dùng tự tạo mạng ảo, router, và quản lý IP.
Cấu hình Controller
# Cài đặt Neutron và các plugin
yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y
# Cấu hình neutron.conf
vim /etc/neutron/neutron.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, nova, oslo_concurrency) ...
[DEFAULT]
core_plugin = ml2
service_plugins = router # Kích hoạt router plugin
allow_overlapping_ips = true
# Cấu hình ml2_conf.ini
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan # Sử dụng VXLAN cho mạng tenant
mechanism_drivers = linuxbridge,l2population
extension_drivers = port_security
[ml2_type_flat]
flat_networks = external
[ml2_type_vxlan]
vni_ranges = 1:1000
[securitygroup]
enable_security_group = true
enable_ipset = true
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.101 # IP của node Controller
l2_population = true
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình l3_agent.ini
vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = linuxbridge
# Cấu hình DHCP agent
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
# Cấu hình Metadata agent
vim /etc/neutron/metadata_agent.ini
[DEFAULT]
nova_metadata_host = openstack-vip.ws.local
metadata_proxy_shared_secret = xier123
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
modprobe br_netfilter
sysctl -p
# Đồng bộ hóa cơ sở dữ liệu và khởi động dịch vụ Neutron
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Cấu hình Dashboard để hỗ trợ Router
vim /etc/openstack-dashboard/local_settings
OPENSTACK_NEUTRON_NETWORK = {
# ...
'enable_router': True,
'enable_quotas': True,
# ...
}
systemctl restart httpd
# Kiểm tra agent Neutron
neutron agent-list
Cấu hình Compute Node
# Cài đặt Neutron Agent
yum install -y openstack-neutron-linuxbridge ebtables ipset
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.107 # IP của node Compute
l2_population = true
[securitygroup]
enable_security_group = false
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Khởi động và kích hoạt dịch vụ Neutron Agent
systemctl enable neutron-linuxbridge-agent.service
systemctl restart neutron-linuxbridge-agent.service
# Khởi động lại dịch vụ Nova Compute
systemctl restart openstack-nova-compute.service
Sau khi cấu hình, người dùng có thể tạo mạng, router và gán IP từ Dashboard hoặc CLI.
OpenStack Project thực chiến
Keepalived + HAProxy (Web Server HA)
Thiết lập HA cho các ứng dụng web.
Chuẩn bị 4 máy ảo: 2 máy cho Load Balancer (LB) và 2 máy cho Web Server.
- LB 1: 172.31.7.88 (VIP: 172.31.7.188)
- LB 2: 172.31.7.89 (VIP: 172.31.7.188)
- Web 1: 172.31.7.78
- Web 2: 172.31.7.79
Cấu hình Web Server (Web 1 & Web 2)
# Cài đặt Java và Tomcat (tải về và giải nén)
# Cấu hình biến môi trường JAVA_HOME và PATH
# Cấu hình Tomcat server.xml
vim conf/server.xml
# Sửa đổi appBase="/data/tomcat/webapps"
# Tạo thư mục webapps và triển khai ứng dụng
mkdir -p /data/tomcat/webapps/myapp
vim /data/tomcat/webapps/myapp/index.html
<h1>Host: 172.31.7.88/89</h1> # Tùy chỉnh để phân biệt server
# Khởi động Tomcat
/path/to/tomcat/bin/catalina.sh start
# Kiểm tra truy cập
# curl http://172.31.7.78:8080/myapp
# curl http://172.31.7.79:8080/myapp
Cấu hình HA Proxy Node
# Cài đặt HAProxy và Keepalived
yum install -y haproxy keepalived
# Cấu hình Keepalived (cho LB 1 - MASTER, LB 2 - BACKUP)
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER # MASTER trên LB1, BACKUP trên LB2
interface eth0
virtual_router_id 55 # Phải giống nhau trên cả hai node
priority 100 # Cao hơn trên MASTER (ví dụ: 100 trên LB1, 90 trên LB2)
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.31.7.188 dev eth0 label eth0:0 # VIP cho dịch vụ web
}
}
systemctl restart keepalived
# Cấu hình HAProxy
vim /etc/haproxy/haproxy.cfg
listen web-service-80
bind 172.31.7.188:80 # Bind với VIP
mode http
balance roundrobin
server web1 172.31.7.78:8080 check inter 3s fall 3 rise 5
server web2 172.31.7.79:8080 check inter 3s fall 3 rise 5
systemctl restart haproxy
# Cấu hình OpenStack Security Group để cho phép VIP và giao thức VRRP (IP Protocol 112)
# neutron security-group-rule-create --protocol 112 --direction ingress --remote-ip-prefix 0.0.0.0/0 default # Hoặc IP của LB
# neutron security-group-rule-create --protocol 112 --direction egress --remote-ip-prefix 0.0.0.0/0 default
Cinder (Lưu trữ Block)
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Cinder
mysql -u root -p
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Cinder và các dịch vụ liên quan (volumev2, volumev3)
openstack user create --domain default --password-prompt cinder
openstack role add --project service --user cinder admin
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
# Đăng ký endpoint cho volumev2 và volumev3
# Cài đặt Cinder API và Scheduler
yum install openstack-cinder -y
# Cấu hình cinder.conf
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:cinder123@openstack-vip.ws.local/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
my_ip = 10.0.0.11 # IP của Controller
[keystone_authtoken]
# ... (cấu hình keystone_authtoken) ...
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Đồng bộ hóa cơ sở dữ liệu
su -s /bin/sh -c "cinder-manage db sync" cinder
# Khởi động và kích hoạt dịch vụ Cinder
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
Cấu hình Compute Node với LVM
# Trên Compute Node:
# Chuẩn bị ổ đĩa cho Cinder (ví dụ: /dev/sdb)
pvcreate /dev/sdb
vgcreate cinder-volumes /dev/sdb
# Cấu hình LVM filter
vim /etc/lvm/lvm.conf
devices {
filter = [ "a/sdb/", "r/.*/"]
}
systemctl restart lvm2-lvmetad.service
# Cài đặt Cinder Volume và Target
yum install openstack-cinder targetcli python-keystone -y
# Cấu hình cinder.conf trên Compute Node
vim /etc/cinder/cinder.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, glance) ...
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
[DEFAULT]
enabled_backends = lvm
my_ip = 172.31.7.107 # IP của Compute Node
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Khởi động và kích hoạt dịch vụ Cinder Volume và Target
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
# Trên Controller Node: Tạo Volume Type và liên kết backend
openstack volume type create lvm
openstack volume type set lvm capabilities=volume_backend_name=Openstack-lvm
Cấu hình Cinder với NFS
# Trên NFS Server (ví dụ: mysql1):
mkdir /data/cinder
vim /etc/exports
/data/cinder *(rw,no_root_squash)
systemctl start nfs
# Trên Controller Node:
vim /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = nfs # Hoặc lvm,nfs
[nfs]
volume_backend_name = openstack-nfs
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs_shares
nfs_mount_point_base = $state_path/mnt
vim /etc/cinder/nfs_shares
172.31.7.105:/data/cinder
chown root.cinder /etc/cinder/nfs_shares
# Khởi động lại các dịch vụ Cinder Controller
systemctl restart openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
# Trên Controller Node: Tạo Volume Type NFS
openstack volume type create nfs
openstack volume type set nfs capabilities=volume_backend_name=openstack-nfs
Sau khi cấu hình, có thể tạo volume và attach vào instance.
Mạng Self-Service
Cho phép người dùng tự tạo mạng, subnet, router và kết nối ra ngoài.
Cấu hình Controller
# Cài đặt Neutron và các plugin
yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y
# Cấu hình neutron.conf
vim /etc/neutron/neutron.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, nova, oslo_concurrency) ...
[DEFAULT]
core_plugin = ml2
service_plugins = router # Kích hoạt router plugin
allow_overlapping_ips = true
# Cấu hình ml2_conf.ini
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan # Sử dụng VXLAN cho mạng tenant
mechanism_drivers = linuxbridge,l2population
extension_drivers = port_security
[ml2_type_flat]
flat_networks = external
[ml2_type_vxlan]
vni_ranges = 1:1000
[securitygroup]
enable_security_group = true
enable_ipset = true
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.101 # IP của node Controller
l2_population = true
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình l3_agent.ini
vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = linuxbridge
# Cấu hình DHCP agent
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
# Cấu hình Metadata agent
vim /etc/neutron/metadata_agent.ini
[DEFAULT]
nova_metadata_host = openstack-vip.ws.local
metadata_proxy_shared_secret = xier123
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
modprobe br_netfilter
sysctl -p
# Đồng bộ hóa cơ sở dữ liệu và khởi động dịch vụ Neutron
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Cấu hình Dashboard để hỗ trợ Router
vim /etc/openstack-dashboard/local_settings
OPENSTACK_NEUTRON_NETWORK = {
# ...
'enable_router': True,
'enable_quotas': True,
# ...
}
systemctl restart httpd
# Kiểm tra agent Neutron
neutron agent-list
Cấu hình Compute Node
# Cài đặt Neutron Agent
yum install -y openstack-neutron-linuxbridge ebtables ipset
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.107 # IP của node Compute
l2_population = true
[securitygroup]
enable_security_group = false
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Khởi động và kích hoạt dịch vụ Neutron Agent
systemctl enable neutron-linuxbridge-agent.service
systemctl restart neutron-linuxbridge-agent.service
# Khởi động lại dịch vụ Nova Compute
systemctl restart openstack-nova-compute.service
Sau khi cấu hình, người dùng có thể tạo mạng, router và gán IP từ Dashboard hoặc CLI.
Tạo Instance với IP tùy chỉnh và đa mạng
Sử dụng CLI để tạo Instance với IP và mạng cụ thể.
# Tạo mạng Internal
openstack network create --share --internal --provider-physical-network internal --provider-network-type flat internal-net
# Tạo subnet cho mạng Internal
openstack subnet create --network internal-net --allocation-pool start=10.10.0.50,end=10.10.0.100 --dns-nameserver 223.6.6.6 --gateway 10.10.0.1 --subnet-range 10.10.0.0/21 internal-sub
# Lấy ID của các mạng
EXTERNAL_NET_ID=$(openstack network show external-net -f value -c id)
INTERNAL_NET_ID=$(openstack network show internal-net -f value -c id)
# Tạo Instance với 1 IP (mạng External)
openstack server create --flavor m1.nano --image cirros --nic net-id=$EXTERNAL_NET_ID --security-group default --key-name mykey instance-external-ip --availability-zone RegionOne:openstack-node1.ws.local
# Tạo Instance với 1 IP tùy chỉnh (mạng External)
openstack server create --flavor m1.nano --image cirros --nic net-id=$EXTERNAL_NET_ID,v4-fixed-ip=172.31.7.88 --security-group default --key-name mykey instance-custom-external --availability-zone RegionOne:openstack-node1.ws.local
# Tạo Instance với 2 IP (1 External, 1 Internal)
openstack server create --flavor m1.nano --image cirros \
--nic net-id=$EXTERNAL_NET_ID,v4-fixed-ip=172.31.7.90 \
--nic net-id=$INTERNAL_NET_ID,v4-fixed-ip=10.10.0.55 \
--security-group default --key-name mykey instance-multi-ip \
--availability-zone RegionOne:openstack-node1.ws.local
# Lưu ý:
# - Cần cấu hình các giao diện mạng vật lý trên Compute Node tương ứng với 'physical_interface_mappings' trong linuxbridge_agent.ini.
# - Cấu hình mạng trên VM (trong /etc/sysconfig/network-scripts/ifcfg-ethX hoặc /etc/netplan/...) để nhận IP từ DHCP hoặc cấu hình tĩnh.
# - Đối với CentOS 6, cần cấu hình địa chỉ MAC cho card mạng để OpenStack nhận diện đúng.
# - Đối với CentOS 7+, disable NetworkManager quản lý card mạng nếu cần: NM_CONTROLLED=no trong tệp ifcfg-*.
OpenStack VM Type Adjustment & Cross-Host Migration
Kiểm tra và điều chỉnh Quota
Kiểm tra quota hiện tại:
openstack quota show --domain Default admin # Hoặc theo project
# neutron quota-show admin # Lệnh cũ
Thay đổi quota (trên Controller Node):
# Cấu hình tệp /etc/neutron/neutron.conf
[quotas]
quota_network = 10
quota_subnet = 10
quota_port = 5000 # Số lượng port quyết định số lượng VM có thể tạo
quota_driver = neutron.db.quota.driver.DbQuotaDriver
# ... các quota khác ...
systemctl restart neutron*
# Cấu hình Dashboard để hiển thị và cho phép điều chỉnh quota
vim /etc/openstack-dashboard/local_settings
'enable_quotas': True,
systemctl restart httpd
Di chuyển Instance / Thay đổi loại Instance
Quá trình này yêu cầu các node Compute có thể truy cập lẫn nhau và có quyền SSH không cần mật khẩu.
- Đảm bảo người dùng
novacó thể SSH không cần mật khẩu giữa các node Compute và Controller. - Cấu hình
resume_guests_state_on_host_boot=truetrongnova.confđể VM có thể tự khởi động lại sau khi host khởi động. - Thực hiện lệnh di chuyển hoặc thay đổi loại Instance từ Controller.
Cinder (Volume & Snapshot)
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Cinder
mysql -u root -p
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Cinder, các dịch vụ (volumev2, volumev3) và endpoints
# ... (như đã mô tả trong phần Cinder HA) ...
# Cài đặt Cinder API và Scheduler
yum install openstack-cinder -y
# Cấu hình cinder.conf
vim /etc/cinder/cinder.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, oslo_concurrency) ...
[DEFAULT]
my_ip = 10.0.0.11 # IP của Controller
# Đồng bộ hóa cơ sở dữ liệu
su -s /bin/sh -c "cinder-manage db sync" cinder
# Khởi động và kích hoạt dịch vụ Cinder
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
Cấu hình Compute Node với LVM
# Trên Compute Node:
# Chuẩn bị ổ đĩa cho Cinder (ví dụ: /dev/sdb)
pvcreate /dev/sdb
vgcreate cinder-volumes /dev/sdb
# Cấu hình LVM filter
vim /etc/lvm/lvm.conf
devices {
filter = [ "a/sdb/", "r/.*/"]
}
systemctl restart lvm2-lvmetad.service
# Cài đặt Cinder Volume và Target
yum install openstack-cinder targetcli python-keystone -y
# Cấu hình cinder.conf trên Compute Node
vim /etc/cinder/cinder.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, glance) ...
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
[DEFAULT]
enabled_backends = lvm
my_ip = 172.31.7.107 # IP của Compute Node
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Khởi động và kích hoạt dịch vụ Cinder Volume và Target
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
# Trên Controller Node: Tạo Volume Type và liên kết backend
openstack volume type create lvm
openstack volume type set lvm capabilities=volume_backend_name=Openstack-lvm
Cấu hình Cinder với NFS
# Trên NFS Server (ví dụ: mysql1):
mkdir /data/cinder
vim /etc/exports
/data/cinder *(rw,no_root_squash)
systemctl start nfs
# Trên Controller Node:
vim /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = nfs # Hoặc lvm,nfs
[nfs]
volume_backend_name = openstack-nfs
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs_shares
nfs_mount_point_base = $state_path/mnt
vim /etc/cinder/nfs_shares
172.31.7.105:/data/cinder
chown root.cinder /etc/cinder/nfs_shares
# Khởi động lại các dịch vụ Cinder Controller
systemctl restart openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
# Trên Controller Node: Tạo Volume Type NFS
openstack volume type create nfs
openstack volume type set nfs capabilities=volume_backend_name=openstack-nfs
Sau khi cấu hình, có thể tạo volume và attach vào instance.
Cinder (Volume & Snapshot)
Thiết lập dữ liệu
# Tạo cơ sở dữ liệu và người dùng cho Cinder
mysql -u root -p
CREATE DATABASE cinder;
GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'cinder123';
FLUSH PRIVILEGES;
EXIT;
Cấu hình Controller
# Tải biến môi trường admin
source admin-openrc.sh
# Tạo người dùng Cinder, các dịch vụ (volumev2, volumev3) và endpoints
openstack user create --domain default --password-prompt cinder
openstack role add --project service --user cinder admin
openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
# Đăng ký endpoint cho volumev2 và volumev3 với VIP
# Cài đặt Cinder API và Scheduler
yum install openstack-cinder -y
# Cấu hình cinder.conf
vim /etc/cinder/cinder.conf
[database]
connection = mysql+pymysql://cinder:cinder123@openstack-vip.ws.local/cinder
[DEFAULT]
transport_url = rabbit://openstack:openstack123@openstack-vip.ws.local
auth_strategy = keystone
my_ip = 10.0.0.11 # IP của Controller
[keystone_authtoken]
# ... (cấu hình keystone_authtoken) ...
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Đồng bộ hóa cơ sở dữ liệu
su -s /bin/sh -c "cinder-manage db sync" cinder
# Khởi động và kích hoạt dịch vụ Cinder
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
Cấu hình Compute Node với LVM
# Trên Compute Node:
# Chuẩn bị ổ đĩa cho Cinder (ví dụ: /dev/sdb)
pvcreate /dev/sdb
vgcreate cinder-volumes /dev/sdb
# Cấu hình LVM filter
vim /etc/lvm/lvm.conf
devices {
filter = [ "a/sdb/", "r/.*/"]
}
systemctl restart lvm2-lvmetad.service
# Cài đặt Cinder Volume và Target
yum install openstack-cinder targetcli python-keystone -y
# Cấu hình cinder.conf trên Compute Node
vim /etc/cinder/cinder.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, glance) ...
[lvm]
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group = cinder-volumes
target_protocol = iscsi
target_helper = lioadm
[DEFAULT]
enabled_backends = lvm
my_ip = 172.31.7.107 # IP của Compute Node
[oslo_concurrency]
lock_path = /var/lib/cinder/tmp
# Khởi động và kích hoạt dịch vụ Cinder Volume và Target
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
# Trên Controller Node: Tạo Volume Type và liên kết backend
openstack volume type create lvm
openstack volume type set lvm capabilities=volume_backend_name=Openstack-lvm
Cấu hình Cinder với NFS
# Trên NFS Server (ví dụ: mysql1):
mkdir /data/cinder
vim /etc/exports
/data/cinder *(rw,no_root_squash)
systemctl start nfs
# Trên Controller Node:
vim /etc/cinder/cinder.conf
[DEFAULT]
enabled_backends = nfs # Hoặc lvm,nfs
[nfs]
volume_backend_name = openstack-nfs
volume_driver = cinder.volume.drivers.nfs.NfsDriver
nfs_shares_config = /etc/cinder/nfs_shares
nfs_mount_point_base = $state_path/mnt
vim /etc/cinder/nfs_shares
172.31.7.105:/data/cinder
chown root.cinder /etc/cinder/nfs_shares
# Khởi động lại các dịch vụ Cinder Controller
systemctl restart openstack-cinder-api.service openstack-cinder-scheduler.service openstack-cinder-volume.service
# Trên Controller Node: Tạo Volume Type NFS
openstack volume type create nfs
openstack volume type set nfs capabilities=volume_backend_name=openstack-nfs
Sau khi cấu hình, có thể tạo volume và attach vào instance.
Mạng Self-Service
Cho phép người dùng tự tạo mạng, subnet, router và kết nối ra ngoài.
Cấu hình Controller
# Cài đặt Neutron và các plugin
yum install openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge ebtables -y
# Cấu hình neutron.conf
vim /etc/neutron/neutron.conf
# ... (cấu hình database, transport_url, auth_strategy, keystone_authtoken, nova, oslo_concurrency) ...
[DEFAULT]
core_plugin = ml2
service_plugins = router # Kích hoạt router plugin
allow_overlapping_ips = true
# Cấu hình ml2_conf.ini
vim /etc/neutron/plugins/ml2/ml2_conf.ini
[ml2]
type_drivers = flat,vlan,vxlan
tenant_network_types = vxlan # Sử dụng VXLAN cho mạng tenant
mechanism_drivers = linuxbridge,l2population
extension_drivers = port_security
[ml2_type_flat]
flat_networks = external
[ml2_type_vxlan]
vni_ranges = 1:1000
[securitygroup]
enable_security_group = true
enable_ipset = true
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.101 # IP của node Controller
l2_population = true
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình l3_agent.ini
vim /etc/neutron/l3_agent.ini
[DEFAULT]
interface_driver = linuxbridge
# Cấu hình DHCP agent
vim /etc/neutron/dhcp_agent.ini
[DEFAULT]
interface_driver = linuxbridge
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
# Cấu hình Metadata agent
vim /etc/neutron/metadata_agent.ini
[DEFAULT]
nova_metadata_host = openstack-vip.ws.local
metadata_proxy_shared_secret = xier123
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
modprobe br_netfilter
sysctl -p
# Đồng bộ hóa cơ sở dữ liệu và khởi động dịch vụ Neutron
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/sh -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugins/ml2/ml2_conf.ini upgrade head" neutron
systemctl enable neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
systemctl start neutron-server.service neutron-linuxbridge-agent.service neutron-dhcp-agent.service neutron-metadata-agent.service neutron-l3-agent.service
# Cấu hình Dashboard để hỗ trợ Router
vim /etc/openstack-dashboard/local_settings
OPENSTACK_NEUTRON_NETWORK = {
# ...
'enable_router': True,
'enable_quotas': True,
# ...
}
systemctl restart httpd
# Kiểm tra agent Neutron
neutron agent-list
Cấu hình Compute Node
# Cài đặt Neutron Agent
yum install -y openstack-neutron-linuxbridge ebtables ipset
# Cấu hình linuxbridge_agent.ini
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings = external:eth0,internal:eth1
[vxlan]
enable_vxlan = true
local_ip = 172.31.7.107 # IP của node Compute
l2_population = true
[securitygroup]
enable_security_group = false
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
# Cấu hình kernel
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p
# Khởi động và kích hoạt dịch vụ Neutron Agent
systemctl enable neutron-linuxbridge-agent.service
systemctl restart neutron-linuxbridge-agent.service
# Khởi động lại dịch vụ Nova Compute
systemctl restart openstack-nova-compute.service
Sau khi cấu hình, người dùng có thể tạo mạng, router và gán IP từ Dashboard hoặc CLI.
Tạo Instance với IP tùy chỉnh và đa mạng
Sử dụng CLI để tạo Instance với IP và mạng cụ thể.
# Tạo mạng Internal
openstack network create --share --internal --provider-physical-network internal --provider-network-type flat internal-net
# Tạo subnet cho mạng Internal
openstack subnet create --network internal-net --allocation-pool start=10.10.0.50,end=10.10.0.100 --dns-nameserver 223.6.6.6 --gateway 10.10.0.1 --subnet-range 10.10.0.0/21 internal-sub
# Lấy ID của các mạng
EXTERNAL_NET_ID=$(openstack network show external-net -f value -c id)
INTERNAL_NET_ID=$(openstack network show internal-net -f value -c id)
# Tạo Instance với 1 IP (mạng External)
openstack server create --flavor m1.nano --image cirros --nic net-id=$EXTERNAL_NET_ID --security-group default --key-name mykey instance-external-ip --availability-zone RegionOne:openstack-node1.ws.local
# Tạo Instance với 1 IP tùy chỉnh (mạng External)
openstack server create --flavor m1.nano --image cirros --nic net-id=$EXTERNAL_NET_ID,v4-fixed-ip=172.31.7.88 --security-group default --key-name mykey instance-custom-external --availability-zone RegionOne:openstack-node1.ws.local
# Tạo Instance với 2 IP (1 External, 1 Internal)
openstack server create --flavor m1.nano --image cirros \
--nic net-id=$EXTERNAL_NET_ID,v4-fixed-ip=172.31.7.90 \
--nic net-id=$INTERNAL_NET_ID,v4-fixed-ip=10.10.0.55 \
--security-group default --key-name mykey instance-multi-ip \
--availability-zone RegionOne:openstack-node1.ws.local
# Lưu ý:
# - Cần cấu hình các giao diện mạng vật lý trên Compute Node tương ứng với 'physical_interface_mappings' trong linuxbridge_agent.ini.
# - Cấu hình mạng trên VM (trong /etc/sysconfig/network-scripts/ifcfg-ethX hoặc /etc/netplan/...) để nhận IP từ DHCP hoặc cấu hình tĩnh.
# - Đối với CentOS 6, cần cấu hình địa chỉ MAC cho card mạng để OpenStack nhận diện đúng.
# - Đối với CentOS 7+, disable NetworkManager quản lý card mạng nếu cần: NM_CONTROLLED=no trong tệp ifcfg-*.