4.8、增加compute
1、前期准备
1)compute又叫nova,是OpenStack中的计算组织控制器。OpenStack中实例(instances)生命周期的所有活动都由Nova处理。这样使得Nova成为一个负责管理计算资源、网络、认证、所需可扩展性的平台。但是,Nova自身并没有提供任何虚拟化能力,相反它使用libvirtAPI来与被支持的Hypervisors(kvm、xen、vmware等)交互。
2)创建nova库,并创建nova用户
mysql -uroot -ptn1Pi6Ytm
>CREATE DATABASE nova;
>GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'RYgv0rg7p';
>GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'RYgv0rg7p';
3)初始化环境变量
source admin-openrc.sh
4)创建nova用户,密码为hsSNsqc43
openstack user create --domain default--password-prompt nova
5)添加admin角色到nova用户
openstack role add --project service --usernova admin
6)创建nova服务实例
openstack service create--name nova --description"OpenStack Compute" compute
7)创建api端点
openstack endpoint create --region RegionOne compute public http://controller:8774/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne compute internal http://controller:8774/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne compute admin http://controller:8774/v2/%\(tenant_id\)s
2、安装包并配置(controller上操作)
1)安装包
yum install -y openstack-nova-api openstack-nova-cert openstack-nova-conductor openstack-nova-console openstack-nova-novncproxy openstack-nova-scheduler Python-novaclient
2)编辑配置文件
vim /etc/nova/nova.conf //更改或增加配置
[database]
connection= mysql://nova:RYgv0rg7p@controller/nova
[DEFAULT]
rpc_backend=rabbit
my_ip=192.168.16.111
auth_strategy=keystone
network_api_class= nova.network.neutronv2.api.API
security_group_api= neutron
linuxnet_interface_driver= nova.network.linux_net.NeutronLinuxBridgeInterfaceDriver
firewall_driver= nova.virt.firewall.NoopFirewallDriver
enabled_apis=osapi_compute,metadata
verbose=true
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= nova
password= hsSNsqc43
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[vnc]
vncserver_listen= $my_ip
vncserver_proxyclient_address= $my_ip
[glance]
host= controller
[oslo_concurrency]
lock_path= /var/lib/nova/tmp
3)同步数据创建nova库
su -s /bin/sh -c "nova-manage db sync" nova
4)启动服务
systemctl enable openstack-nova-api.service \
openstack-nova-cert.service openstack-nova-consoleauth.service \
openstack-nova-scheduler.service openstack-nova-conductor.service \
openstack-nova-novncproxy.service
systemctlstart openstack-nova-api.service \
openstack-nova-cert.service openstack-nova-consoleauth.service \
openstack-nova-scheduler.service openstack-nova-conductor.service \
openstack-nova-novncproxy.service
3、安装包并配置(compute上操作)
1)安装nova-compute包
yum install -y openstack-nova-compute sysfsutils
2)编辑配置文件
vim /etc/nova/nova.conf //更改或增加如下配置
[DEFAULT]
rpc_backend= rabbit
auth_strategy= keystone
my_ip= 192.168.16.112
network_api_class= nova.network.neutronv2.api.API
security_group_api= neutron
linuxnet_interface_driver= nova.network.linux_net.NeutronLinuxBridgeInterfaceDriver
firewall_driver= nova.virt.firewall.NoopFirewallDriver
verbose=true
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= nova
password= hsSNsqc43
[vnc]
enabled= True
vncserver_listen= 0.0.0.0
vncserver_proxyclient_address= $my_ip
novncproxy_base_url= http://controller:6080/vnc_auto.html
[glance]
host= controller
[oslo_concurrency]
lock_path= /var/lib/nova/tmp
3)开启支持虚拟化
使用如下命令检查你的机器cpu是否支持虚拟化
egrep -c '(vmx|svm)' /proc/cpuinfo
如果得到的数字大于0,说明是支持的,否则说明不支持,若为0,需要编辑如下配置文件
vim /etc/nova/nova.conf //编辑
[libvirt]
virt_type= qemu
4)启动服务
systemctl enable libvirtd.service openstack-nova-compute.service
systemctl start libvirtd.service openstack-nova-compute.service
4、验证操作
1)执行脚本
source admin-openrc.sh
2)列出服务组件
nova service-list
共有5个:nova-consoleauth、nova-conductor、nova-scheduler、nova-cert、nova-compute
3)列出api端点,一共有9组:nova三组,glance三组,keystone三组
nova endpoints
注意:如果有提示:WARNING:nova has no endpoint in ! Available endpoints for this service
可以忽略掉,也可以编辑 admin-openrc.sh 增加一行 export OS_REGION_NAME=RegionOne
4)列出镜像
nova image-list
4.9、增加networking
1、前期准备
1)Networking又叫做Neutron,是Openstack必不可少的组件,它其实是网络虚拟化的实现工具,可以让我们模拟出路由器、交换机、网卡等网络设备。关于Neutron的电书:
https://yeasy.gitbooks.io/openstack_understand_neutron/content/
Neutron支持两种网络模式,第一种是非常简单的网络架构,它仅支持是让实例连接外网,不支持自定义网络、路由器以及浮动ip。只有管理员或者授权的用户有权限去管理网络。第二种网络功能比较强大,支持自定义网络管理,支持自建路由器并且也支持浮动ip。即使没有授权的用户也可以管理网络,支持用户自己配置和管理。
2)创建库、授权账号
mysql -uroot -ptn1Pi6Ytm
>CREATE DATABASE neutron;
>GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'localhost' IDENTIFIED BY 'quidyOC50';
>GRANT ALL PRIVILEGES ON neutron.* TO 'neutron'@'%' IDENTIFIED BY 'quidyOC50';
3)执行脚本
source admin-openrc.sh
4)创建neutron用户(密码为mdcGVl29i)
openstack user create --domain default --password-prompt neutron
5)把admin角色添加到neutron用户里
openstack role add --project service --userneutron admin
6)创建neutron实例
openstack service create --name neutron --description "OpenStack Networking" network
7)创建networking服务api终端
openstack endpoint create --region RegionOne network public http://controller:9696
openstack endpoint create --region RegionOne network internal http://controller:9696
openstack endpoint create --region RegionOne network admin http://controller:9696
2、配置
1)安装组件
yum install -y openstack-neutron openstack-neutron-ml2 openstack-neutron-linuxbridge python-neutronclient ebtables ipset
2)配置服务端组件
vim /etc/neutron/neutron.conf //更改或增加
[DEFAULT]
core_plugin= ml2
service_plugins=
rpc_backend= rabbit
auth_strategy= keystone
notify_nova_on_port_status_changes= True
notify_nova_on_port_data_changes= True
nova_url= http://controller:8774/v2
verbose= True
[database]
connection= mysql://neutron:quidyOC50@controller/neutron
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= neutron
password= mdcGVl29i
[nova]
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
region_name= RegionOne
project_name= service
username= nova
password= hsSNsqc43
[oslo_concurrency]
lock_path= /var/lib/neutron/tmpl
3)配置ml2 插件
vim /etc/neutron/plugins/ml2/ml2_conf.ini //更改或增加
[ml2]
type_drivers= flat,vlan
tenant_network_types=
mechanism_drivers= linuxbridge
extension_drivers= port_security
[ml2_type_flat]
flat_networks= public
[securitygroup]
enable_ipset= True
4)编辑linux桥接agent
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini //增加或更改
[linux_bridge]
physical_interface_mappings= public:eno16777736
[vxlan]
enable_vxlan= False
[agent]
prevent_arp_spoofing= True
[securitygroup]
enable_security_group= True
firewall_driver= neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
5)配置dhcp agent
vim /etc/neutron/dhcp_agent.ini //增加或更改
[DEFAULT]
interface_driver= neutron.agent.linux.interface.BridgeInterfaceDriver
dhcp_driver= neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata= True
verbose= True
3、配置元数据agent
编辑配置文件
vim /etc/neutron/metadata_agent.ini //更改或增加
[DEFAULT]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_region= RegionOne
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= neutron
password= mdcGVl29i
nova_metadata_ip= controller
metadata_proxy_shared_secret= m8uhmQTu2
verbose= True
说明:需要删除掉配置文件里原有的 auth_url auth_region admin_tenant_name admin_user admin_password
4、compute使用网络(controller上操作)
vim /etc/nova/nova.conf //更改或添加
[neutron]
url= http://controller:9696
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
region_name= RegionOne
project_name= service
username= neutron
password= mdcGVl29i
service_metadata_proxy= True
metadata_proxy_shared_secret= m8uhmQTu2
5、启动服务
1)创建ml2插件配置文件创建软连接
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
2)生成数据
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
3)重启compute api服务
systemctl restart openstack-nova-api.service
4)启动服务
systemctl enable neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.servicelsystemctlstart neutron-server.service \
neutron-linuxbridge-agent.service neutron-dhcp-agent.service \
neutron-metadata-agent.servicelsystemctlenable neutron-l3-agent.service
systemctl start neutron-l3-agent.service
6、配置compute节点(compute上操作)
1)安装组件
yum install -y openstack-neutron openstack-neutron-linuxbridge ebtables ipset
2)配置普通组件
vim /etc/neutron/neutron.conf //更改或增加
[DEFAULT]
rpc_backend= rabbit
auth_strategy= keystone
verbose= True
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= neutron
password= mdcGVl29i
[oslo_concurrency]
lock_path= /var/lib/neutron/tmp
3)配置linux桥接agent
vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini
[linux_bridge]
physical_interface_mappings =public:eno16777736
[vxlan]
enable_vxlan = False
[agent]
prevent_arp_spoofing = True
[securitygroup]
enable_security_group = True
firewall_driver =neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
4)配置compute使用网络
vim /etc/nova/nova.conf //更改或增加
[neutron]
url= http://controller:9696
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
region_name= RegionOne
project_name= service
username= neutron
password= mdcGVl29i
5)启动服务
systemctl restart openstack-nova-compute.service
systemctl enable neutron-linuxbridge-agent.service
systemctl start neutron-linuxbridge-agent.service
7、验证配置
1)执行环境变量脚本
source admin-openrc.sh
2)列出所有的扩展
neutron ext-list
3)列出所有agent
neutron agent-list //agenttype如下:
Linuxbridge agent
Linuxbridge agent
DHCP agent
Metadata agent
必须要有4个,否则说明上面的某个步骤配置有问题。
4.10、增加dashboard
1、horizon
1)安装包
yum install -y openstack-dashboard
2)编辑配置文件
vim /etc/openstack-dashboard/local_settings //更改或增加
OPENSTACK_HOST= "controller"
ALLOWED_HOSTS= ['*', ]
CACHES= {
'default':{
'BACKEND':'django.core.cache.backends.locmem.LocMemCache',
'LOCATION':'127.0.0.1:11211',
} }
OPENSTACK_KEYSTONE_DEFAULT_ROLE= "user"
OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT= True
OPENSTACK_API_VERSIONS= {
"identity":3,
"volume":2,
}
TIME_ZONE= "Asia/Chongqing"
3)重启服务
systemctl restart httpd.service memcached.service
此时可以去访问 http://controller/dashboard 了,使用账号admin或者demon用户登陆即可,域为default
4.11、增加block storage
1、前期准备
blockstorage又叫做cinder,用来给openstack提供存储服务,比如我们在阿里云购买一台云主机,同时想购买容量大的磁盘,通常叫做云盘,这个云盘就是blockstorage。
1)创建库并授权cinder用户
mysql -uroot -ptn1Pi6Ytml
>CREATE DATABASE cinder;
>GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'localhost' IDENTIFIED BY 'O3bwbpoZ3';
>GRANT ALL PRIVILEGES ON cinder.* TO 'cinder'@'%' IDENTIFIED BY 'O3bwbpoZ3';
2)执行初始化脚本
source admin-openrc.sh
3)创建cinder用户 (密码为hf8LX9bow)
openstack user create --domain default --password-prompt cinder
4)添加admin角色
openstack role add --project service --user cinder admin
5)创建cinder和cinderv2 实例
openstack service create --name cinder \
--description "OpenStack Block Storage" volume
openstack service create --name cinderv2 \
--description "OpenStack Block Storage" volumev2
6)创建块存储服务api终端
openstack endpoint create --region RegionOne volume public http://controller:8776/v1/%\(tenant_id\)s
openstack endpoint create --region RegionOne volume internal http://controller:8776/v1/%\(tenant_id\)s
openstack endpoint create --region RegionOne volume admin http://controller:8776/v1/%\(tenant_id\)s
openstackendpoint create --region RegionOne volumev2 public http://controller:8776/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne volumev2 internal http://controller:8776/v2/%\(tenant_id\)s
openstack endpoint create --region RegionOne volumev2 admin http://controller:8776/v2/%\(tenant_id\)s
2、安装和配置
1)安装包
yum install -y openstack-cinder python-cinderclient
2)编辑配置文件
vim /etc/cinder/cinder.conf //更改或增加
[database]
connection= mysql://cinder:O3bwbpoZ3@controller/cinder
[DEFAULT]
rpc_backend= rabbit
auth_strategy= keystone
my_ip= 192.168.16.111
verbose= True
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= cinder
password= hf8LX9bow
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[oslo_concurrency]
lock_path= /var/lib/cinder/tmp
3)同步数据
su -s /bin/sh -c "cinder-manage db sync" cinder
4)配置compute使用块存储
vim /etc/nova/nova.conf
[cinder]
os_region_name=RegionOne
5)启动服务
systemctl restart openstack-nova-api.service
systemctl enable openstack-cinder-api.service openstack-cinder-scheduler.service
systemctl start openstack-cinder-api.service openstack-cinder-scheduler.service
3、配置storage节点(compute上操作)
我们理应需要再准备一台单独的机器来做storage服务的,但是为了节省资源,我们就那compute节点和storage节点共用。这里需要为compute(storage)节点再增加一块磁盘(/dev/sdb)作为存储磁盘。
1)安装lvm
yum install -y lvm2
2)启动服务
systemctl enable lvm2-lvmetad.service
systemctl start lvm2-lvmetad.service
3)创建物理卷
pvcreate /dev/sdb
4)创建卷组
vgcreate cinder-volumes /dev/sdb
5)编辑配置文件
vim /etc/lvm/lvm.conf
devices{
filter = [ "a/sdb/","r/.*/"]
说明:如果还有第三块磁盘,应该再加上
filter= [ "a/sda/", "a/sdb/", "r/.*/"]
6)安装包
yum install -y openstack-cinder targetclipython-oslo-policy
7)编辑配置文件
vim /etc/cinder/cinder.conf
[DEFAULT]
rpc_backend= rabbit
auth_strategy= keystone
my_ip= 192.168.16.112
enabled_backends= lvm
glance_host= controller
verbose= True
[database]
connection= mysql://cinder:O3bwbpoZ3@controller/cinder
[oslo_messaging_rabbit]
rabbit_host= controller
rabbit_userid= openstack
rabbit_password= o3NXovnz5
[keystone_authtoken]
auth_uri= http://controller:5000
auth_url= http://controller:35357
auth_plugin= password
project_domain_id= default
user_domain_id= default
project_name= service
username= cinder
password= hf8LX9bow
[lvm]
volume_driver= cinder.volume.drivers.lvm.LVMVolumeDriver
volume_group= cinder-volume
liscsi_protocol= iscsi
iscsi_helper= lioadm
[oslo_concurrency]
lock_path= /var/lib/cinder/tmp
4、启动和验证
1)启动服务(compute上操作)
systemctl enable openstack-cinder-volume.service target.service
systemctl start openstack-cinder-volume.service target.service
2)验证操作(controller上操作)
执行初始化脚本
source admin-openrc.sh
列出服务
cinder service-list
4.12、运行实例
1、创建公网网络
1)执行初始化脚本
source admin-openrc.sh
2)创建网络
neutron net-create public--shared --provider:physical_network public \
--provider:network_type flat
3)创建子网
neutron subnet-create public 192.168.16.0/24 --name public \
--allocation-pool start=192.168.16.10,end=192.168.16.30 \
--dns-nameserver 119.29.29.29 --gateway 192.168.16.2l
说明:这里的公网,实际上是虚拟机用的那个网段,我们暂时把它作为公网,在这里因为涉及到dhcp服务,会和局域网内的路由器上的dhcp服务产生冲突,所以需要先把路由器上的dhcp服务关掉。
2、创建key
1)执行初始化脚本
source demo-openrc.sh
2)生成密钥
ssh-keygen-q -N ""
nova keypair-add --pub-key ~/.ssh/id_rsa.pub mykey
3)验证密钥
nova keypair-list
4)增加安全组规则
nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
5)允许ssh 访问
nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
3、配置实例选项
1)执行初始化脚本
source demo-openrc.sh
2)列出实例类型
nova flavor-list
3)列出所有镜像
nova image-list
4)列出可用网络
neutron net-list
5)列出安全组
nova secgroup-list
6)运行实例
nova boot --flavor m1.tiny --image cirros --nic net-id=PUBLIC_NET_ID \
--security-group default --key-name mykeypublic-instance
说明:这里的PUBLIC_NET_ID需要替换为可用网络里面public网络的id
7)检测实例状态
nova list
4、连接实例
1)使用vnc连接(使用下面命令可以列出vnc的连接)
nova get-vnc-console public-instance novnc
2)验证网络(在实例里面)
ping -c 4 192.168.16.2
3)远程连接实例
首先用 nova list 查看实例的ip(假如为192.168.16.33)
验证ip:
ping -c4 192.168.16.33
远程ssh登录:
ssh cirros@192.168.16.33
5、增加云盘
1)先执行初始化脚本
source demo-openrc.sh
2)创建一个2G的云盘,名字为volume1
cinder create --display-name volume1 2
3)列出所有云盘
cinder list
4)把云盘挂到实例中
nova volume-attach INSTANCE_NAME VOLUME_ID
说明:INSTACE_NAME可以用nova list查看,VOLUME_ID就是用cinder list查看到的云盘id
5)列出已经挂上的云盘
nova volume-list
6)登陆到实例查看云盘
ssh cirros@192.168.16.33
sudo fdisk -l
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-04/142971.htm
