1. 程式人生 > 實用技巧 >【轉】基於openstack安裝部署私有云詳細圖文教程

【轉】基於openstack安裝部署私有云詳細圖文教程

更新時間:2017年02月04日 08:46:53 轉載作者:朱培

本文中作者通過自身基於OpenStack搭建私有云平臺的實戰經驗,對OpenStack實施私有云落地的需求進行梳理,綜合產生個人的觀點和評價並和讀者分享。

本文主要分享的是雲端計算、openstack的使用、私有云平臺建設、雲伺服器雲硬碟的構建和使用。從基本概念入手到私有云建設,資訊量非常大。對於openstack的安裝部署都是從官方文件中一步步的介紹,內容非常詳細。

一、雲端計算 基本概念

雲端計算(cloud computing)是基於網際網路的相關服務的增加、使用和交付模式,通常涉及通過網際網路來提供動態易擴充套件且經常是虛擬化的資源。雲是網路、網際網路的一種比喻說法。過去在圖中往往用雲來表示電信網,後來也用來表示網際網路和底層基礎設施的抽象。因此,雲端計算甚至可以讓你體驗每秒10萬億次的運算能力,擁有這麼強大的計算能力可以模擬核爆炸、預測氣候變化和市場發展趨勢。使用者通過電腦、筆記本、手機等方式接入資料中心,按自己的需求進行運算。

雲端計算分類

簡單來說,就是把應用程式和資料都放在由大量伺服器組成的雲中,使用者需要什麼只要購買相應服務並使用即可。

雲端計算分為私有云、公有云、混合雲。

雲端計算的服務分類:基礎設施即服務、平臺即服務、軟體即服務。

  1. 超大規模。“雲”具有相當的規模,Google雲端計算已經擁有100多萬臺伺服器,亞馬遜、IBM、微軟和Yahoo等公司的“雲”均擁有幾十萬臺伺服器。“雲”能賦予使用者前所未有的計算能力。
  2. 虛擬化。雲端計算支援使用者在任意位置使用各種終端獲取服務。所請求的資源來自“雲”,而不是固定的有形的實體。應用在“雲”中某處執行,但實際上使用者無需瞭解應用執行的具體位置,只需要一臺筆記本或一個PDA,就可以通過網路服務來獲取各種能力超強的服務。
  3. 高可靠性。“雲”使用了資料多副本容錯、計算節點同構可互換等措施來保障服務的高可靠性,使用雲端計算比使用本地計算機更加可靠。
  4. 通用性。雲端計算不針對特定的應用,在“雲”的支撐下可以構造出於變萬化的應用,同一片“雲”可以同時支撐不同的應用執行。
  5. 高可伸縮性。“雲”的規模可以動態伸縮,滿足應用和使用者規模增長的需要。
  6. 按需服務。“雲”是一個龐大的資源池,使用者按需購買,像自來水、電和煤氣那樣計費。
  7. 極其廉價。“雲”的特殊容錯措施使得可以採用極其廉價的節點來構成雲;“雲”的自動化管理使資料中心管理成本大幅降低;“雲”的公用性和通用性使資源的利用率大幅提升;“雲”設施可以建在電力資源豐富的地區,從而大幅降低能源成本。

二、Openstack基本概念

OpenStack是一個開源的雲端計算管理平臺專案,由幾個主要的元件組合起來完成

具體工作。OpenStack支援幾乎所有型別的雲環境,專案目標是提供實施簡單、

可大規模擴充套件、豐富、標準統一的雲端計算管理平臺。OpenStack通過各種互補的

服務提供了基礎設施即服務(IaaS)的解決方案,每個服務提供API以進行整合。

常見元件:

  • Dashboard(web專案)
  • Keystone(許可權管理)
  • Nova(管理虛擬機器)
  • Nova-network(管理網路流量和ip)
  • Glance(映象管理專案)
  • Cinder(磁碟管理)
  • Swift(網盤,物件)

基礎的系統圖

三、Openstack安裝部署

下面來說一說openstack的安裝部署。首先說明openstack的整體安裝非常複雜,文末提供官方安裝文件下載,我就是根據這個英文的官方文件來安裝部署的。以下內容是參照官方文件“openstack-install-guide-yum-icehouse.pdf”來的。

首先需要準備3臺linux的機器。我這裡選用的是centos6.6的64位的系統。配置IP地址,關閉防火牆,修改主機名。

• Controller Node: 1 processor, 2 GB memory, and 5 GB storage

• Compute01: 1 processor, 512 MB memory, and 5 GB storage

• Compute02 Node: 1 processor, 2 GB memory, and 10 GB storage

我這裡controller的ip地址是:192.168.44.147

computer01:192.168.44.148

computer02:192.168.44.149

基本環境配置

以下內容是在controller機器上配置的。

1、資料庫安裝。

因為需要一個數據庫,所以這裡選用了mysql資料庫。

1 yum install mysql mysql-server MySQL-python

編輯/etc/my.cnf檔案,在裡面新增如下內容,主要意思就是設定編碼為utf-8。

1 2 3 4 5 default-storage-engine = innodb innodb_file_per_table collation-server = utf8_general_ci init-connect = 'SET NAMES utf8' character-set-server = utf8

然後啟動服務,開機啟動。

1 2 3 4 # service mysqld start # chkconfig mysqld on # mysql_install_db # mysql_secure_installation

賦權,使其可以遠端登入。

1 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'a';

2、openstack基本包安裝。

1 2 3 4 5 6 7 8 9 10 # yum install yum-plugin-priorities # yum install http://repos.fedorapeople.org/repos/openstack/openstackicehouse/rdo-release-icehouse-3.noarch.rpm # yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8. noarch.rpm # yum install openstack-utils # yum install openstack-selinux

3、安裝訊息佇列

1 yum install qpid-cpp-server

啟動服務

1 2 service qpidd start chkconfig qpidd on

許可權認證服務(keystone)

安裝許可權認證服務:

1 yum install openstack-keystone python-keystoneclient -y

建立使用者,寫入到配置檔案中:

1 2 openstack-config --set /etc/keystone/keystone.conf \ database connection mysql://keystone:KEYSTONE_DBPASS@controller/keystone

建立keystone資料庫表:

1 2 3 4 5 6 7 $ mysql -u root -p mysql> CREATE DATABASE keystone; mysql> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' \ IDENTIFIED BY 'KEYSTONE_DBPASS'; mysql> GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' \ IDENTIFIED BY 'KEYSTONE_DBPASS'; mysql> exit

自動生成表:

1 su -s /bin/sh -c "keystone-manage db_sync" keystone

設定使用者環境變數:

1 2 3 4 5 6 7 8 ADMIN_TOKEN=$(openssl rand -hex 10) echo $ADMIN_TOKEN openstack-config --set /etc/keystone/keystone.conf DEFAULT \ admin_token $ADMIN_TOKEN # keystone-manage pki_setup --keystone-user keystone --keystone-group keystone # chown -R keystone:keystone /etc/keystone/ssl # chmod -R o-rwx /etc/keystone/ssl

啟動keystone服務:

1 2 service openstack-keystone start chkconfig openstack-keystone on

將admin_token設定到環境變數中去。

1 2 export OS_SERVICE_TOKEN=$ADMIN_TOKEN export OS_SERVICE_ENDPOINT=http://controller:35357/v2.0

建立管理員使用者,預設的使用者名稱為admin,密碼為ADMIN_PASS,你可以自定義修改:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [root@controller keystone]# keystone user-create --name=admin --pass=ADMIN_PASS --email=ADMIN_EMAIL +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email | ADMIN_EMAIL| | enabled | True | |id| 332f5ecb18c64bf687b154facd629fb6 | | name | admin | | username | admin | +----------+----------------------------------+ [root@controller keystone]# keystone role-create --name=admin +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ |id| ab5da2c50d7443efb0514e84c2b4adb7 | | name | admin | +----------+----------------------------------+ [root@controller keystone]# keystone tenant-create --name=admin --description="Admin Tenant" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | Admin Tenant | | enabled | True | | id | b89723a38b154eeea6416a83b293b0ad | | name| admin | +-------------+----------------------------------+ [root@controller keystone]# keystone user-role-add --user=admin --tenant=admin --role=admin [root@controller keystone]# keystone user-role-add --user=admin --role=_member_ --tenant=admin [root@controller keystone]#

建立一個許可權認證服務,因為我這裡的主機名是controller,所以下面有http://controller:35357/v2.0這些資訊,可以自定義修改:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 [root@controller keystone]# keystone service-create --name=keystone --type=identity \ > --description="OpenStack Identity" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description |OpenStack Identity| | enabled | True | | id | 4bfd5f39b86c45edb92d5c0488987dd8 | | name| keystone | | type| identity | +-------------+----------------------------------+ [root@controller keystone]# keystone endpoint-create \ > --service-id=$(keystone service-list | awk '/ identity / {print $2}') \ > --publicurl=http://controller:5000/v2.0 \ > --internalurl=http://controller:5000/v2.0 \ > --adminurl=http://controller:35357/v2.0 +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://controller:35357/v2.0 | | id | 0350b72901a141498fe48304b13a1b98 | | internalurl | http://controller:5000/v2.0| | publicurl | http://controller:5000/v2.0| |region |regionOne | | service_id | 4bfd5f39b86c45edb92d5c0488987dd8 | +-------------+----------------------------------+ [root@controller keystone]# keystone user-create --name=demo --pass=DEMO_PASS --email=DEMO_EMAIL +----------+----------------------------------+ | Property | Value | +----------+----------------------------------+ | email |DEMO_EMAIL| | enabled | True | |id| b44a9a1462d74f4e928b3b339289a2ae | | name | demo | | username | demo | +----------+----------------------------------+ [root@controller keystone]# keystone tenant-create --name=demo --description="Demo Tenant" +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | Demo Tenant| | enabled | True | | id | 7bd79509ee184a2098ca0644679b60a8 | | name| demo | +-------------+----------------------------------+ [root@controller keystone]# keystone user-role-add --user=demo --role=_member_ --tenant=demo [root@controller keystone]#

為了方便我們取到token,我們可以vi admin-openrc.sh,然後新增如下內容:

1 2 3 4 export OS_USERNAME=admin export OS_PASSWORD=ADMIN_PASS export OS_TENANT_NAME=admin export OS_AUTH_URL=http://controller:35357/v2.0

在每次關機重啟之後都要重新執行下面的命令,讓環境變數起作用。否則會報”Expecting an auth URL via either –os-auth-url or env[OS_AUTH_URL]”的錯誤:

1 source admin-openrc.sh

我們可以使用下面的命令檢視keystone目前的使用者有哪些:

1 keystone user-list

測試效果:

開啟restclient-ui-3.5-jar-with-dependencies.jar來測試效果:

url地址是: http://192.168.44.147:5000/v2.0/

訪問成功。

配置映象服務(glance)

在controller伺服器中安裝服務:

1 2 3 4 5 6 7 8 9 yum install openstack-glance python-glanceclient openstack-config --set /etc/glance/glance-api.conf database \ connection mysql://glance:GLANCE_DBPASS@controller/glance openstack-config --set /etc/glance/glance-registry.conf database \ connection mysql://glance:GLANCE_DBPASS@controller/glance

在mysql資料庫中建立glance資料庫:

1 2 3 4 5 6 7 8 $ mysql -u root -p mysql> CREATE DATABASE glance; mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' \ IDENTIFIED BY 'GLANCE_DBPASS'; mysql> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' \ IDENTIFIED BY 'GLANCE_DBPASS'; flush privileges;

自動生成表:

1 su -s /bin/sh -c "glance-manage db_sync" glance

在keystone上建立使用者:

1 2 keystone user-create --name=glance --pass=GLANCE_PASS [email protected] $ keystone user-role-add --user=glance --tenant=service --role=admin

配置授權服務:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ auth_uri http://controller:5000 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ auth_host controller openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ auth_port 35357 openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ auth_protocol http openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ admin_tenant_name service openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ admin_user glance openstack-config --set /etc/glance/glance-api.conf keystone_authtoken \ admin_password GLANCE_PASS openstack-config --set /etc/glance/glance-api.conf paste_deploy \ flavor keystone openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ auth_uri http://controller:5000 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ auth_host controller openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ auth_port 35357 openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ auth_protocol http openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ admin_tenant_name service openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ admin_user glance openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken \ admin_password GLANCE_PASS openstack-config --set /etc/glance/glance-registry.conf paste_deploy \ flavor keystone

啟動服務:

1 2 3 4 service openstack-glance-api start # service openstack-glance-registry start # chkconfig openstack-glance-api on # chkconfig openstack-glance-registry on

建立服務:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 $ keystone service-create --name=glance --type=image \ --description="OpenStack Image Service" $ keystone endpoint-create \ --service-id=$(keystone service-list | awk '/ image / {print $2}') \ --publicurl=http://controller:9292 \ --internalurl=http://controller:9292 \ --adminurl=http://controller:9292 [root@controller ~]# keystone service-create --name=glance --type=image \ > --description="OpenStack Image Service" /usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability. _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning) +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Image Service | | enabled | True | | id | a45f77cfc12c42d19a45a6ea12cdfc51 | | name| glance | | type| image | +-------------+----------------------------------+ [root@controller ~]# keystone endpoint-create \ > --service-id=$(keystone service-list | awk '/ image / {print $2}') \ > --publicurl=http://controller:9292 \ > --internalurl=http://controller:9292 \ > --adminurl=http://controller:9292 +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://controller:9292 | | id | 75deb2d2f85e4b7b88fe18bf5fca1a87 | | internalurl | http://controller:9292 | | publicurl | http://controller:9292 | |region |regionOne | | service_id | a45f77cfc12c42d19a45a6ea12cdfc51 | +-------------+----------------------------------+

建立映象,先將下載好的cirros-0.3.2-x86_64-disk.img放置在/root目錄下,然後執行下面的命令:

複製程式碼程式碼如下:
glance image-create --name "cirros-0.3.2-x86_64" --disk-format qcow2 \
--container-format bare --is-public True --progress < cirros-0.3.2-x86_64-disk.img

檢視映象列表:

1 glance image-list

在前面我們已經對kvm虛擬化有所瞭解,所以我們現在知道qcow2就是一個映象檔案。

伺服器管理(Nova)

對於虛擬機器管理我們需要從controller和computer01進行配置。

先來看controller的配置:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 yum install openstack-nova-api openstack-nova-cert openstack-nova-conductor \ openstack-nova-console openstack-nova-novncproxy openstack-nova-scheduler \ python-novaclient $ mysql -u root -p mysql> CREATE DATABASE nova; mysql> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' \ IDENTIFIED BY 'NOVA_DBPASS'; mysql> GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' \ IDENTIFIED BY 'NOVA_DBPASS'; openstack-config --set /etc/nova/nova.conf database connection mysql://nova:NOVA_DBPASS@controller/nova openstack-config --set /etc/nova/nova.conf DEFAULT rpc_backend qpid openstack-config --set /etc/nova/nova.conf DEFAULT qpid_hostname controller openstack-config --set /etc/nova/nova.conf DEFAULT my_ip 192.168.44.147 openstack-config --set /etc/nova/nova.conf DEFAULT vncserver_listen 192.168.216.210 openstack-config --set /etc/nova/nova.conf DEFAULT vncserver_proxyclient_address 192.168.44.147 openstack-config --set /etc/nova/nova.conf DEFAULT auth_strategy keystone openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_uri http://controller:5000 openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_host controller openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_protocol http openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_port 35357 openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_user nova openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_tenant_name service openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_password NOVA_PASS $ keystone user-create --name=nova --pass=NOVA_PASS [email protected] $ keystone user-role-add --user=nova --tenant=service --role=admin $ keystone service-create --name=nova --type=compute \ --description="OpenStack Compute" $ keystone endpoint-create \ --service-id=$(keystone service-list | awk '/ compute / {print $2}') \ --publicurl=http://controller:8774/v2/%\(tenant_id\)s \ --internalurl=http://controller:8774/v2/%\(tenant_id\)s \ --adminurl=http://controller:8774/v2/%\(tenant_id\)s

然後是computer01的配置:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 yum install openstack-nova-compute openstack-config --set /etc/nova/nova.conf database connection mysql://nova:NOVA_DBPASS@controller/nova openstack-config --set /etc/nova/nova.conf DEFAULT auth_strategy keystone openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_uri http://controller:5000 openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_host controller openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_protocol http openstack-config --set /etc/nova/nova.conf keystone_authtoken auth_port 35357 openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_user nova openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_tenant_name service openstack-config --set /etc/nova/nova.conf keystone_authtoken admin_password NOVA_PASS openstack-config --set /etc/nova/nova.conf DEFAULT rpc_backend qpid openstack-config --set /etc/nova/nova.conf DEFAULT qpid_hostname controller openstack-config --set /etc/nova/nova.conf DEFAULT my_ip 192.168.44.148 openstack-config --set /etc/nova/nova.conf DEFAULT vnc_enabled True openstack-config --set /etc/nova/nova.conf DEFAULT vncserver_listen 0.0.0.0 openstack-config --set /etc/nova/nova.conf DEFAULT vncserver_proxyclient_address 192.168.44.148 openstack-config --set /etc/nova/nova.conf DEFAULT novncproxy_base_url http://controller:6080/vnc_auto.html openstack-config --set /etc/nova/nova.conf DEFAULT glance_host controller openstack-config --set /etc/nova/nova.conf libvirt virt_type kvm

啟動服務:

1 2 3 4 5 6 service libvirtd start service messagebus start service openstack-nova-compute start chkconfig libvirtd on chkconfig messagebus on chkconfig openstack-nova-compute on

網路服務配置

在controller端:

1 2 3 4 5 openstack-config --set /etc/nova/nova.conf DEFAULT \ network_api_class nova.network.api.API openstack-config --set /etc/nova/nova.conf DEFAULT \ security_group_api nova

在computer01端:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 yum install openstack-nova-network openstack-nova-api # openstack-config --set /etc/nova/nova.conf DEFAULT \ network_api_class nova.network.api.API # openstack-config --set /etc/nova/nova.conf DEFAULT \ security_group_api nova # openstack-config --set /etc/nova/nova.conf DEFAULT \ network_manager nova.network.manager.FlatDHCPManager # openstack-config --set /etc/nova/nova.conf DEFAULT \ firewall_driver nova.virt.libvirt.firewall.IptablesFirewallDriver # openstack-config --set /etc/nova/nova.conf DEFAULT \ network_size 254 # openstack-config --set /etc/nova/nova.conf DEFAULT \ allow_same_net_traffic False # openstack-config --set /etc/nova/nova.conf DEFAULT \ multi_host True # openstack-config --set /etc/nova/nova.conf DEFAULT \ send_arp_for_ha True # openstack-config --set /etc/nova/nova.conf DEFAULT \ share_dhcp_address True # openstack-config --set /etc/nova/nova.conf DEFAULT \ force_dhcp_release True # openstack-config --set /etc/nova/nova.conf DEFAULT \ flat_network_bridge br100 # openstack-config --set /etc/nova/nova.conf DEFAULT \ flat_interface eth1 # openstack-config --set /etc/nova/nova.conf DEFAULT \ public_interface eth0

nova network-create demo-net –bridge br100 –multi-host T \

–fixed-range-v4 88.8.8.16/28

然後使用nova net-list來檢視:

建立虛擬機器

1、配置ssh密碼登入:

1 ssh-keygen

2、增加公鑰到openstack環境中:

1 nova keypair-add --pub-key ~/.ssh/id_rsa.pub demo-key

3、驗證是否配置成功:

1 2 3 nova keypair-list nova flavor-list

4、建立例項:

複製程式碼程式碼如下: nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic netid=DEMO_NET_ID\
--security-group default --key-name demo-key demo-instance1

說明:

DEMO_NET_ID:指的是nova net-list的ID。

demo-instance1指的是虛擬機器的名字。

例如我的成功執行如下:

nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic net-id=55fc305f-570f-4d4f-89d0-ce303e589f20 \
--security-group default --key-name demo-key tfjt

5、使用nova list進行檢視。

從這裡我們看到我這上面有一個ip地址192.168.44.17.這個地址就是浮動IP。

6、配置浮動IP

浮動ip

1 nova-manage floating create --ip_range=192.168.44.16/28

檢視可用地址

1 nova-manage floating list

nova floating-ip-create

給建立的虛擬機器繫結浮動ip,這個7bc0086…就是我之前建立的虛擬機器的ID。後面接上IP地址即可。

1 nova add-floating-ip 7bc00086-1870-4367-9f05-666d5067ccff 192.168.44.17

監聽

cpdump -n -i eth0 icmp

在controller上:

nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0

nova secgroup-add-rule default tcp 22 22 0.0.0.0/0

7、使用下面的命令可以輸出一個url地址:

1 nova get-vnc-console tfjt novnc

8、我們可以在瀏覽器中進行訪問。

到這裡為止,我們的雲伺服器就算完成了。可以在瀏覽器上訪問我們的雲伺服器,怎麼樣是不是很激動。

介面服務(dashboard)

上面我們可以看到很多操作是在終端進行的,那麼肯定是有介面版的,所以我們在computer02中進行配置。

1、安裝服務

yum install memcached python-memcached mod_wsgi openstack-dashboard

2、檔案配置。

在controller中

配置/etc/openstack-dashboard/local_settings。修改為如下內容。

1 2 3 4 5 6 7 8 9 10 11 ALLOWED_HOSTS = ['*'] CACHES = { 'default': { 'BACKEND' : 'django.core.cache.backends.memcached.MemcachedCache', 'LOCATION' : '127.0.0.1:11211' } } OPENSTACK_HOST = "controller"

3、連線

1 2 3 4 5 6 setsebool -P httpd_can_network_connect on service httpd start # service memcached start # chkconfig httpd on # chkconfig memcached on

4、瀏覽器中訪問。

1 http://192.168.44.147/dashboard/project/

使用者名稱就是我們之前配置的admin,密碼是ADMIN_PASS

在這個介面版裡面的各種操作我這裡就不細說了,可以自己去體驗。

在這裡可以看到我們的雲伺服器例項。

雲硬碟服務(cinder)

瞭解過阿里雲或者騰訊雲的就知道,裡面都有一個雲硬碟服務,可以給我們的機器增加磁碟。

在controller端:

1 2 3 4 5 6 7 8 9 10 yum stall openstack-cinde openstack-config --set /etc/cinder/cinder.conf \ database connection mysql://cinder:CINDER_DBPASS@controller/cinder mysql> CREATE DATABASE cinder; mysql> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' \ IDENTIFIED BY 'CINDER_DBPASS'; mysql> GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' \ IDENTIFIED BY 'CINDER_DBPASS';

建立資料庫表:

1 # su -s /bin/sh -c "cinder-manage db sync" cinder

建立使用者並賦予角色:

1 2 $ keystone user-create --name=cinder [email protected] $ keystone user-role-add --user=cinder --tenant=service --role=admin

許可權控制配置:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 # openstack-config --set /etc/cinder/cinder.conf DEFAULT \ auth_strategy keystone # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_uri http://controller:5000 # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_host controller # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_protocol http # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_port 35357 # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_user cinder # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_tenant_name service # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_password CINDER_PASS

訊息佇列配置:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT rpc_backend qpid # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT qpid_hostname controller $ keystone service-create --name=cinder --type=volume --description="OpenStack Block Storage" $ keystone endpoint-create \ --service-id=$(keystone service-list | awk '/ volume / {print $2}') \ --publicurl=http://controller:8776/v1/%\(tenant_id\)s \ --internalurl=http://controller:8776/v1/%\(tenant_id\)s \ --adminurl=http://controller:8776/v1/%\(tenant_id\)s $ keystone service-create --name=cinderv2 --type=volumev2 --description="OpenStack Block Storage v2" $ keystone endpoint-create \ --service-id=$(keystone service-list | awk '/ volumev2 / {print $2}') \ --publicurl=http://controller:8776/v2/%\(tenant_id\)s \ --internalurl=http://controller:8776/v2/%\(tenant_id\)s \ --adminurl=http://controller:8776/v2/%\(tenant_id\)s service openstack-cinder-api start # service openstack-cinder-scheduler start # chkconfig openstack-cinder-api on # chkconfig openstack-cinder-scheduler on cinder service-list openstack-config --set /etc/cinder/cinder.conf \ DEFAULT qpid_hostname controller cinder --debug list keystone user-create --name=cinder --pass=CINDER_PASS [email protected] openstack-config --set /etc/cinder/cinder.conf \ DEFAULT my_ip 192.168.44.147

在node端(computer02)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 pvcreate /dev/sdb # vgcreate cinder-volumes /dev/sdb yum install openstack-cinder scsi-target-utils # openstack-config --set /etc/cinder/cinder.conf DEFAULT \ auth_strategy keystone # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_uri http://controller:5000 # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_host controller # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_protocol http # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ auth_port 35357 # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_user cinder # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_tenant_name service # openstack-config --set /etc/cinder/cinder.conf keystone_authtoken \ admin_password CINDER_PASS # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT rpc_backend qpid # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT qpid_hostname controller # openstack-config --set /etc/cinder/cinder.conf \ database connection mysql://cinder:CINDER_DBPASS@controller/cinde # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT my_ip MANAGEMENT_INTERFACE_IP_ADDRESS # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT glance_host controller # openstack-config --set /etc/cinder/cinder.conf \ DEFAULT iscsi_helper tgtadm

配置檔案中:

vi /etc/tgt/targets.conf

1 include /etc/cinder/volumes/*

啟動服務:

1 2 3 4 # service openstack-cinder-volume start # service tgtd start # chkconfig openstack-cinder-volume on # chkconfig tgtd on

建立磁碟:

1 cinder create --display-name myVolume 1

檢視磁碟列表:

1 cinder list

然後再介面端檢視雲硬碟的配置並進行掛載:

在雲伺服器上掛載磁碟:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 $ mkfs.ext3 /dev/vdb1 $ mkdir /mnt/test $ mount /dev/vdb1 /mnt/test $ mount $ fdisk /dev/vdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x64817ea3. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-2097151, default 2048): +1G Value out of range. First sector (2048-2097151, default 2048): +512M Last sector, +sectors or +size{K,M,G} (1048576-2097151, default 2097151): Using default value 2097151 Command (m for help): p Disk /dev/vdb: 1073 MB, 1073741824 bytes 16 heads, 63 sectors/track, 2080 cylinders, total 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x64817ea3 Device Boot Start End Blocks Id System /dev/vdb1 1048576 2097151 524288 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. $ df -h

總結:整個操作流程非常複雜,我也是花了幾天才慢慢搭建好的,這其實也就是個基礎,給的其實是一個思路,後面需要怎樣的擴充套件可以根據自己的業務需要進行不同的設定。對於不明白的地方可以查閱官方文件。

openstack官方文件下載地址:https://www.jb51.net/books/530692.html

轉載自:https://www.jb51.net/article/104511.htm