當時因爲Quantum 還有很多BUG 網絡服務仍使用nova-network
整體規劃
各個主機都要有不同的主機名,openstack使用hostname區別內部的各個主機。
三臺主機:
control.test.com 控制節點
compute-01.test.com 計算節點
compute-02.test.com 計算節點
主機ip地址:
Control.test.com:
eth0: 192.168.3.164 /24(公網) eht1: 192.168.4.164/24(私網)
compute-01.test.com:
eth0: 192.168.3.165/24(公網) eth1: 192.168.4.165/24(私網)
compute-02.test.com:
eth0: 192.168.3.166/24(公網) eth1: 192.168.4.166/24(私網)
………….
計算節點 保留eth1網口給虛擬機用
其中 192.168.3.0/24 作爲物理機IP段(可認爲是公網IP,)
192.168. 4.0/24 作爲物理機服務之間的通訊
192.168.3.168---192.168.3.190 作爲虛擬機 Floating_ip 段(分配給虛擬機,從外部可以直接訪問的,可以認爲是公網IP地址)
虛擬機網段規劃:
本次採用的是vlan模式,並且是多nova-network服務模式
虛擬機內整體網段:
10.100.0.0/24 , 再在此段上劃分出vlan段
劃分的三個vlan段:
10.100.0.0/24 vlan_id 2
虛擬機遷移:
配置nfs ,來做遷移
由於程序中會對共享目錄中的uid進行操作,所以需要nfs server 和client端的uid是一致的,至少必須不同主機之間nova用戶的uid是一致的,libvirt-bin用戶也要一致
所以用存儲服務器(192.168.3.166) 作爲nfs server
別的計算節點 作爲 client端
兩個計算節點之間測試遷移
虛擬機掛載額外磁盤:
openstack使用LVM來劃分磁盤,利用tgt + open_iscsi來實現局域網內磁盤設備的利用
現在我們提供磁盤的主機是存儲服務器(192.168.3.166),同時也是一個nfs server節點。
當要給虛擬機劃分磁盤時,首先利用lvm在ubuntu2劃分指定大小的一塊磁盤,然後利用tgt 服務,把磁盤聲明出去,運行目標虛擬機的物理主機會去找到這個盤,並登陸使用,分配給其上的虛擬機使用。
源
目前Folsom進入ubuntu 12.04的官方的源,不過需要你手工添加。
- cat <<EOF >>/etc/apt/sources.list
- deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-proposed/folsom main
- deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/folsom main
- EOF
運行下面命令
- apt-get install ubuntu-cloud-keyring
- apt-get update
Hostname設置
- cat /etc/hostname
- control
- cat /etc/hosts
- 127.0.0.1 localhost
- 192.168.4.165 compute-01.test.com compute-01
- 192.168.4.166 compute-02.test.com compute-02
- hostname
- control
- hostname -f
- control.test.com
網絡
直接設置 /etc/network/interface
- auto lo
- iface lo inet loopback
- auto eth0
- iface eth0 inet static
- address 192.168.3.164
- netmask 255.255.255.0
- gateway 192.168.3.1
- auto eth1
- iface eth1 inet static
- address 192.168.4.164
- netmask 255.255.255.0
重啓服務
- /etc/init.d/networking restart
設置IP轉發
- sed -i -r 's/^\s*#(net\.ipv4\.ip_forward=1.*)/\1/' /etc/sysctl.conf
- sysctl -p
一、安裝控制節點
安裝 NTP服務
編輯 /etc/ntp.conf ,在 server ntp.ubuntu.com 下添加兩行
- server ntp.ubuntu.com
- server 127.127.1.0
- fudge 127.127.1.0 stratum 10
或者直接運行下面命令
- sed -i 's/server ntp.ubuntu.com/server ntp.ubuntu.com\nserver 127.127.1.0\nfudge 127.127.1.0 stratum 10/g' /etc/ntp.conf
重啓NTP服務
- service ntp restart
安裝mysql
- apt-get -y install mysql-server python-mysqldb
安裝時輸入mysql的root用戶密碼:root-pass
設置監聽Ip
- sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
重啓服務
- service mysql restart
創建數據庫
- mysql -uroot -proot-pass <<EOF
- CREATE DATABASE nova;
- GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'nova-pass';
- CREATE DATABASE glance;
- GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'glance-pass';
- CREATE DATABASE keystone;
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%'IDENTIFIED BY ' keystone-pass';
- CREATE DATABASE cinder;
- GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%'IDENTIFIED BY 'cinder-pass';
- FLUSH PRIVILEGES;
- EOF
安裝RabbitMQ
- apt-get -y install rabbitmq-server
把默認密碼 guest,改成rabbit-pass
- rabbitmqctl change_password guest rabbit-pass
注意:如果hostname 和 hosts文件中主機名不相同服務無法啓動
安裝keystone
keystone 認證服務:openstack中各個組件之間傳遞消息,或者用戶對虛擬機的管理都要通過keystone認證,以保證某個請求是合法的
- apt-get install keystone python-keystone python-keystoneclient
默認keystone使用sqlite ,改爲mysql, 刪除原來的數據庫文件
- rm /var/lib/keystone/keystone.db
配置 /etc/keystone/keystone.conf
- [DEFAULT]
- admin_token = 012345SECRET99TOKEN012345
- bind_host = 0.0.0.0
- public_port = 5000
- admin_port = 35357
- compute_port = 8774
- verbose = True
- debug = True
- log_file = keystone.log
- log_dir = /var/log/keystone
- log_config = /etc/keystone/logging.conf
- [sql]
- connection = mysql://keystone:[email protected]:3306/keystone
- idle_timeout = 200
重啓服務和初始化數據庫
- service keystone restart
- keystone-manage db_sync
查看數據庫中是否創建了這些表,版本不一樣可能表也不一樣
配置tenant,user 和 role
tenant : 租戶,代替了原本的project的概念,一個tenant 應該是一個整個的工程,在這個tenant裏面可以創建user, 可以給這個user 配置role , 然後這個user 可以在這個 tenant 裏面創建虛擬機,配置安全組等
創建tenant
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 tenant-create --name openstackDemo --description "Default Tenant" --enabled true
在這個tenant裏創建用戶 adminUser
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-create --tenant_id b5815b046cfe47bb891a7b64119e7f80 --name adminUser --pass secretword --enabled true
創建默認角色 admin 和memberRole
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 role-create --name admin
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 role-create --name memberRole
給 openstackDemo tenant 裏的adminUser 賦予admin 權限
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-role-add --user_id a4c2d43f80a549a19864c89d759bb3fe --tenant_id b5815b046cfe47bb891a7b64119e7f80 --role_id e3d9d157cc95410ea45d23bbbc2e5c10
這個命令沒有輸出,如果有多個tenant 的話要賦予權限給相應
創建一個Service tenant , 這個tenant裏包括所有的服務用戶
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 tenant-create --name service --description "Service Tenant" --enabled true
在service tenant裏 創建 glance service 用戶
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-create --tenant_id eb7e0c10a99446cfa14c244374549e9d --name glance --pass glance --enabled true
把 admin 角色賦予glance 服務用戶
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-role-add --user_id 46b2667a7807483d983e0b4037a1623b --tenant_id eb7e0c10a99446cfa14c244374549e9d --role_id e3d9d157cc95410ea45d23bbbc2e5c10
這個命令沒有輸出
在service tenant 裏創建nova service 用戶
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-create --tenant_id eb7e0c10a99446cfa14c244374549e9d --name nova --pass nova --enabled true
給nova服務用戶賦予 admin 角色
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-role-add --user_id 54b3776a8707834d983e0b4037b1345c --tenant_id eb7e0c10a99446cfa14c244374549e9d --role_id e3d9d157cc95410ea45d23bbbc2e5c10
在service tenant 裏創建ec2 服務用戶
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-create --tenant_id eb7e0c10a99446cfa14c244374549e9d --name ec2 --pass ec2 --enabled true
給ec2服務用戶賦予admin角色
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 user-role-add --user_id 32e7668b8707834d983e0b4037b1345c --tenant_id eb7e0c10a99446cfa14c244374549e9d --role_id e3d9d157cc95410ea45d23bbbc2e5c10
keystone 上定義service 端點: endpoint
endpoint上定義了openstack 各個服務的 API endpoint (入口)
定義方式有兩種,
1,使用模板文件:
/etc/keystone/default_catalog.templates
2. 使用數據庫作爲後端
我們使用數據庫的方式配置endpoint
修改 /etc/keystone/keystone.conf 的 [catalog] 默認使用數據庫
如果使用模板文件,則修改爲:
創建keystone 服務 和 服務端點(service endpoints)
創建identity服務
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 service-create --name=keystone --type=identity --description="Keystone Identity Service"
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 endpoint-create --region RegionOne --service_id=15c11a23667e427e91bc31335b45f4bd --publicurl=http://192.168.4.164:5000/v2.0 --internalurl=http://192.168.4.164:5000/v2.0 --adminurl=http://192.168.4.164:35357/v2.0
創建compute 服務 ,需要爲endpoint制定一個tenant
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 service-create --name=nova --type=compute --description="Nova Compute Service"
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 endpoint-create --region RegionOne --service_id=abc0f03c02904c24abdcc3b7910e2eed --publicurl='http://192.168.4.164:8774/v2/%(tenant_id)s' --internalurl='http://192.168.4.164:8774/v2/%(tenant_id)s' --adminurl='http://192.168.4.164:8774/v2/%(tenant_id)s'
定義volume service ,也需要制定 tenant
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 service-create --name=volume --type=volume --description="Nova Volume Service"
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 endpoint-create --region RegionOne --service_id=1ff4ece13c3e48d8a6461faebd9cd38f --publicurl='http://192.168.4.164:8776/v1/%(tenant_id)s' --internalurl='http://192.168.4.164:8776/v1/%(tenant_id)s' --adminurl='http://192.168.4.164:8776/v1/%(tenant_id)s'
定義 p_w_picpath 服務
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 service-create --name=glance --type=p_w_picpath --description="Glance Image Service"
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 endpoint-create --region RegionOne --service_id=7d5258c490144c8c92505267785327c1 --publicurl=http://192.168.4.165:9292/v1 --internalurl=http://192.168.4.165:9292/v1 --adminurl=http://192.168.4.165:9292/v1
注意:如果glance服務從控制節點分開,命令中端口是9292的IP都要改成glance服務器的IP
定義EC2服務
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 service-create --name=ec2 --type=ec2 --description="EC2 Compatibility Layer"
- keystone --token 012345SECRET99TOKEN012345 --endpoint http://192.168.4.164:35357/v2.0 endpoint-create --region RegionOne --service_id=181cdad1d1264387bcc411e1c6a6a5fd --publicurl=http://192.168.4.164:8773/services/Cloud --internalurl=http://192.168.4.164:8773/services/Cloud --adminurl=http://192.168.4.164:8773/services/Admin
驗證認證服務的正確性
- sudo apt-get install curl openssl
- curl -d '{"auth": {"tenantName": "adminTenant", "passwordCredentials":{"username": "adminUser", "password": "secretword"}}}' -H "Content-type:application/json" http://192.168.4.164:35357/v2.0/tokens | python -mjson.tool
安裝glance服務
在存儲節點安裝鏡像服務器 (不一定要安裝在控制節點,可以單獨拿出一臺物理主機部署glance)如果分開的話要先安裝計算節點服務(sudo apt-get install nova-compute nova-network nova-api novnc)或先創建計算節點中所用到的賬戶,因爲nova會使用到計算節點的賬戶
- apt-get -y install glance glance-api python-glanceclient glance-common
注意:如果glance服務和控制節點分開,必須在glance服務器安裝python-keystone模塊,否則glance服務無法啓動
刪掉默認的數據庫,因爲後面要配置mysql數據庫
- sudo rm /var/lib/glance/glance.sqlite
配置
編輯/etc/glance/glance-api.conf 和 /etc/glance/glance-registry.conf
- sql_connection = mysql://glance:[email protected]/glance
- auth_host = 192.168.4.164
- admin_tenant_name = service
- admin_user = glance
- admin_password = glance-pass
編輯 /etc/glance/glance-api.conf
- #notifier_strategy = noop
- notifier_strategy = rabbit
- #rabbit_password = guest
- rabbitrabbit_password = rabbit-pass
運行下面命令
- cat <<EOF >>/etc/glance/glance-api.conf
- flavor = keystone+cachemanagement
- EOF
- cat <<EOF >>/etc/glance/glance-registry.conf
- flavor = keystone
- EOF
重啓服務
- service glance-api restart && service glance-registry restart
在ubuntu12.04 glance 數據表是在 version control 之下的,運行下面的步驟
如果glance服務和控制機分開的話要安裝python-mysqldb
- glance-manage version_control 0
- glance-manage db_sync
- sudo service glance-registry restart
驗證glance
- glance --version
獲取測試鏡像
- mkdir /tmp/p_w_picpaths
- cd /tmp/p_w_picpaths/
- wget http://smoser.brickies.net/ubuntu/ttylinux-uec/ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz
- tar -zxvf ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz
注意:上傳鏡像時,如果glance服務從控制節點分開,下面命令中的IP:127.0.0.1都要改成keystone服務器的IP(內網ip)
上傳kernel
- glance --os_username=adminUser --os_password=secretword --os_tenant=openstackDemo --os_auth_url=http://127.0.0.1:5000/v2.0 add name="tty-linux-kernel" disk_format=aki container_format=aki < ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz
上傳initrd
- glance --os_username=adminUser --os_password=secretword --os_tenant=openstackDemo --os_auth_url=http://127.0.0.1:5000/v2.0 add name="tty-linux-ramdisk" disk_format=ari container_format=ari < ttylinux-uec-amd64-12.1_2.6.35-22_1-loader
上傳鏡像
- glance --os_username=adminUser --os_password=secretword --os_tenant=openstackDemo --os_auth_url=http://127.0.0.1:5000/v2.0 add name="tty-linux" disk_format=ami container_format=ami kernel_id=599907ff-296d-4042-a671-d015e34317d2 ramdisk_id=7d9f0378-1640-4e43-8959-701f248d999d < ttylinux-uec-amd64-12.1_2.6.35-22_1.img
- glance --os_username=adminUser --os_password=secretword --os_tenant=openstackDemo --os_auth_url=http://127.0.0.1:5000/v2.0 index
上面的例子使用 --os_username, --os_password, --os_tenant, --os_auth_url ,也可以使用 OS_*環境變量
例如: vi openrc
- export OS_USERNAME=adminUser
- export OS_TENANT_NAME=openstackDemo
- export OS_PASSWORD=secretword
- export OS_AUTH_URL=http://192.168.4.164:5000/v2.0/
- export OS_REGION_NAME=RegionOne
安裝nova服務
- apt-get -y install nova-api nova-cert nova-common nova-scheduler python-nova python-novaclient nova-consoleauth novnc nova-novncproxy
配置
編輯 /etc/nova/api-paste.ini
- auth_host = 192.168.4.164
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = nova
- admin_password = nova
編輯文件 /etc/nova/nova.conf
- [DEFAULT]
- logdir=/var/log/nova
- state_path=/var/lib/nova
- lock_path=/run/lock/nova
- verbose=False
- api_paste_config=/etc/nova/api-paste.ini
- scheduler_driver=nova.scheduler.simple.SimpleScheduler
- s3_host=192.168.4.164
- ec2_host=192.168.4.164
- ec2_dmz_host=192.168.4.164
- rabbit_host=192.168.4.164
- rabbitrabbit_password=rabbit-pass
- cc_host=192.168.4.164
- nova_url=http://192.168.4.164:8774/v1.1/
- sql_connection=mysql://nova:[email protected]/nova
- ec2_url=http://192.168.4.164:8773/services/Cloud
- root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
- # Auth
- use_deprecated_auth=false
- auth_strategy=keystone
- keystone_ec2_url=http://192.168.4.164:5000/v2.0/ec2tokens
- # Imaging service
- glance_api_servers=192.168.4.165:9292
- p_w_picpath_service=nova.p_w_picpath.glance.GlanceImageService
- # Vnc configuration
- novnc_enabled=true
- novncproxy_base_url=http://0.0.0.0:6080/vnc_auto.html
- novncproxy_port=6080
- vncserver_proxyclient_address=0.0.0.0
- vncserver_listen=0.0.0.0
- # Network settings
- #network_api_class=nova.network.quantumv2.api.API
- #quantum_url=http://192.168.4.164:9696
- #quantum_auth_strategy=keystone
- #quantum_admin_tenant_name=service
- #quantumquantum_admin_username=quantum
- #quantum_admin_password=
- #quantum_admin_auth_url=http://192.168.4.164:35357/v2.0
- #libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver
- #linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver
- #firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
- ###### NETWORK
- #network_manager=nova.network.manager.FlatDHCPManager
- network_manager=nova.network.manager.VlanManager
- force_dhcp_release=True
- dhcpbridge_flagfile=/etc/nova/nova.conf
- dhcpbridge=/usr/bin/nova-dhcpbridge
- firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver
- public_inter>
- flat_inter>
- vlan_inter>
- flat_network_bridge=br100
- fixed_range=10.100.0.0/24
- multi_host=true
- # Compute #
- #compute_driver=libvirt.LibvirtDriver
- ###### COMPUTE
- libvirt_type=kvm
- connection_type=libvirt
- instanceinstance_name_template=instance-%08x
- api_paste_config=/etc/nova/api-paste.ini
- allow_resize_to_same_host=True
- libvirt_use_virtio_for_bridges=true
- start_guests_on_host_boot=true
- resume_guests_state_on_host_boot=true
- # Cinder #
- volume_api_class=nova.volume.cinder.API
- osapi_volume_listen_port=5900
創建nova數據表
- nova-manage db sync
重啓服務
- service nova-api restart
- service nova-cert restart
- service nova-consoleauth restart
- service nova-scheduler restart
- service nova-novncproxy restart
安裝cinder服務
在存儲節點安裝cinder服務
- apt-get install -y cinder-api cinder-scheduler cinder-volume open-iscsi tgt python-cinderclient
硬盤專門一個分區給volume使用
- pvcreate /dev/sda5
- vgcreate cinder-volumes /dev/sda5
編輯 /etc/cinder/cinder.conf ,直接運行下面命令就可以
- [DEFAULT]
- rootwrap_config = /etc/cinder/rootwrap.conf
- sql_connection = mysql://cinder:[email protected]:3306/cinder
- api_paste_confg = /etc/cinder/api-paste.ini
- iscsi_helper = ietadm
- volume_group = cinder-volumes
- volumevolume_name_template = volume-%s
- rabbitrabbit_password = rabbit-pass
- logdir = /var/log/cinder
- verbose = False
- auth_strategy = keystone
編輯 /etc/cinder/api-paste.ini
- admin_tenant_name = service
- admin_user = cinder
- admin_password = cinder
同步數據庫
- cinder-manage db sync
重啓服務
- service cinder-api restart
- service cinder-scheduler restart
- service cinder-volume restart
nova 命令創建額外存儲
volume-attach Attach a volume to a server.
volume-create Add a new volume.
volume-delete Remove a volume.
volume-detach Detach a volume from a server.
volume-list List all the volumes.
volume-show Show details about a volume.
創建
顯示volume
顯示虛擬機
掛載
顯示volume
掛好的顯示 in-use
卸載
顯示volume
進入虛擬機就會看到 /dev/下面多了個磁盤文件