上面需要的组件,已经很清楚。
基础组件升级内核
- apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码
时间服务器,很多问题都是由于时间不同步造成。
复制代码
MySQL
- apt-get install -y mysql-server python-mysqldb
复制代码
修改 /etc/mysql/my.cnf
- bind-address = 10.0.0.11
-
- [mysqld]
- default-storage-engine = innodb
- innodb_file_per_table
- collation-server = utf8_general_ci
- init-connect = 'SET NAMES utf8'
- character-set-server = utf8
复制代码
重启mysql
复制代码
安全设置
- mysql_install_db
- mysql_secure_installation
复制代码
消息队列RabbitMQ
- apt-get install -y rabbitmq-server
复制代码
keystone安装keystone
- apt-get install -y keystone
复制代码
创建keystone数据库,都是通过 mysql –u root –p 进入
- CREATE DATABASE keystone;
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'KEYSTONE_DBPASS';
- GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'KEYSTONE_DBPASS';
-
- exit;
复制代码
删除sqllite数据库
- rm /var/lib/keystone/keystone.db
复制代码
编辑 /etc/keystone/keystone.conf
- connection = mysql://keystone:KEYSTONE_DBPASS@10.0.0.11/keystone
-
- [DEFAULT]
- admin_token=ADMIN
- log_dir=/var/log/keystone
复制代码
初始化keystone数据库
- service keystone restart
- keystone-manage db_sync
复制代码
设置环境变量
- export OS_SERVICE_TOKEN=ADMIN
- export OS_SERVICE_ENDPOINT=http://10.0.0.11:35357/v2.0
复制代码
创建管理员权力的用户
- keystone user-create --name=admin --pass=admin_pass --email=admin@domain.com
- keystone role-create --name=admin
- keystone tenant-create --name=admin --description="Admin Tenant"
- keystone user-role-add --user=admin --tenant=admin --role=admin
- keystone user-role-add --user=admin --role=_member_ --tenant=admin
复制代码
创建普通用户
- keystone user-create --name=demo --pass=demo_pass --email=demo@domain.com
- keystone tenant-create --name=demo --description="Demo Tenant"
- keystone user-role-add --user=demo --role=_member_ --tenant=demo
复制代码
创建 service 租户
- keystone tenant-create --name=service --description="Service Tenant"
复制代码
定义服务的API的endpoint
- keystone service-create --name=keystone --type=identity --description="OpenStack Identity"
复制代码
创建endpoint
- keystone endpoint-create \
- --service-id=$(keystone service-list | awk '/ identity / {print $2}') \
- --publicurl=http://192.168.100.11:5000/v2.0 \
- --internalurl=http://10.0.0.11:5000/v2.0 \
- --adminurl=http://10.0.0.11:35357/v2.0
复制代码
检测keystone
通过下面命令检查keystone的初始化是否正常
设置环境变量,创建creds 和 admin_creds 两个文件
- cat <<EOF >>/root/creds
- export OS_TENANT_NAME=admin
- export OS_USERNAME=admin
- export OS_PASSWORD=admin_pass
- export OS_AUTH_URL="http://192.168.100.11:5000/v2.0/"
- EOF
- cat <<EOF >>/root/admin_creds
- export OS_USERNAME=admin
- export OS_PASSWORD=admin_pass
- export OS_TENANT_NAME=admin
- export OS_AUTH_URL=http://10.0.0.11:35357/v2.0
- EOF
复制代码
检测
设置环境变量才能进行下面操作
复制代码
这样就可以
- root@controller:~# keystone user-list
- +----------------------------------+-------+---------+------------------+
- | id | name | enabled | email |
- +----------------------------------+-------+---------+------------------+
- | 6f8bcafd62ec4e23ab2be28016829f91 | admin | True | admin@domain.com |
- | 66713a75b7c14f73a1c5a015241f5826 | demo | True | demo@domain.com |
- +----------------------------------+-------+---------+------------------+
- root@controller:~# keystone role-list
- +----------------------------------+----------+
- | id | name |
- +----------------------------------+----------+
- | 9fe2ff9ee4384b1894a90878d3e92bab | _member_ |
- | cd8dec7752d24a028f95657556f7573d | admin |
- +----------------------------------+----------+
- root@controller:~# keystone tenant-list
- +----------------------------------+---------+---------+
- | id | name | enabled |
- +----------------------------------+---------+---------+
- | efc81990ab4c433f94573e2e0fcf08c3 | admin | True |
- | be10dc11d4034b389bef8bbcec657f6f | demo | True |
- | cb45c886bc094f65940ba29d79eab8aa | service | True |
- +----------------------------------+---------+---------+
复制代码
查看日志
日志在/var/log/keystone/ 下,先清空日志,看看日志是否还有错误信息.
- echo "" > /var/log/keystone/keystone-all.log
- echo "" > /var/log/keystone/keystone-manage.log
- tail /var/log/keystone/*
复制代码
GlanceOpenstack组件安装,都比较类似。
- apt-get install -y glance python-glanceclient
复制代码
创建数据库 mysql –u root –p
- CREATE DATABASE glance;
- GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
- GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
-
- exit;
复制代码
keystone创建glance用户和服务
- keystone user-create --name=glance --pass=service_pass --email=glance@domain.com
- keystone user-role-add --user=glance --tenant=service --role=admin
复制代码
设置endpoint
- 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://192.168.100.11:9292 \
- --internalurl=http://10.0.0.11:9292 \
- --adminurl=http://10.0.0.11:9292
复制代码
编辑 /etc/glance/glance-api.conf
- [database]
- connection = mysql://glance:GLANCE_DBPASS@10.0.0.11/glance
-
- [DEFAULT]
- rpc_backend = rabbit
- rabbit_host = 10.0.0.11
-
- [keystone_authtoken]
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = glance
- admin_password = service_pass
-
- [paste_deploy]
- flavor = keystone
复制代码
编辑 /etc/glance/glance-registry.conf
- [database]
- # The file name to use with SQLite (string value)
- #sqlite_db = /var/lib/glance/glance.sqlite
- connection = mysql://glance:GLANCE_DBPASS@10.0.0.11/glance
-
-
- [keystone_authtoken]
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = glance
- admin_password = service_pass
-
- [paste_deploy]
- flavor = keystone
复制代码
重启服务
- service glance-api restart; service glance-registry restart
复制代码
初始化glance数据库
复制代码
上传镜像
- source creds
- glance image-create --name "cirros-0.3.2-x86_64" --is-public true \
- --container-format bare --disk-format qcow2 \
- --location http://cdn.download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img
复制代码
查看镜像
- # glance image-list
- +--------------------------------------+---------------------+-------------+------------------+----------+--------+
- | ID | Name | Disk Format | Container Format | Size | Status |
- +--------------------------------------+---------------------+-------------+------------------+----------+--------+
- | d7a6d71d-4222-44f4-82d0-49c14ba19676 | cirros-0.3.2-x86_64 | qcow2 | bare | 13167616 | active |
- +--------------------------------------+---------------------+-------------+------------------+----------+--------+
复制代码
检测log
- root@controller:~# tail /var/log/glance/*
- ==> /var/log/glance/api.log <==
- 2014-09-02 07:07:12.315 2946 WARNING glance.store.base [-] Failed to configure store correctly:
- Store sheepdog could not be configured correctly. Reason:
- Error in store configuration: [Errno 2] No such file or directory Disabling add method.
- 2014-09-02 07:07:12.316 2946 WARNING glance.store [-] Deprecated: glance.store.
- sheepdog.Store not found in `known_store`.
- Stores need to be explicitly enabled in the configuration file.
复制代码
你会发现log里有类似的所谓错误,这个不是问题。希望glance改进一下这个地方的log。不然让很多新手很郁闷。
Nova安装软件
- apt-get install -y nova-api nova-cert nova-conductor nova-consoleauth \
- nova-novncproxy nova-scheduler python-novaclient
复制代码
创建nova 数据库 mysql –u root –p
- CREATE DATABASE nova;
- GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
- GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
-
- exit;
复制代码
配置keystone
- keystone user-create --name=nova --pass=service_pass --email=nova@domain.com
- keystone user-role-add --user=nova --tenant=service --role=admin
复制代码
设置endpoint
- keystone service-create --name=nova --type=compute --description="OpenStack Compute"
- keystone endpoint-create \
- --service-id=$(keystone service-list | awk '/ compute / {print $2}') \
- --publicurl=http://192.168.100.11:8774/v2/%\(tenant_id\)s \
- --internalurl=http://10.0.0.11:8774/v2/%\(tenant_id\)s \
- --adminurl=http://10.0.0.11:8774/v2/%\(tenant_id\)s
复制代码
编辑 /etc/nova/nova.conf
下面是我的nova.conf 文件的全部内容
- [DEFAULT]
- dhcpbridge_flagfile=/etc/nova/nova.conf
- dhcpbridge=/usr/bin/nova-dhcpbridge
- logdir=/var/log/nova
- state_path=/var/lib/nova
- lock_path=/var/lock/nova
- force_dhcp_release=True
- iscsi_helper=tgtadm
- libvirt_use_virtio_for_bridges=True
- connection_type=libvirt
- root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
- verbose=True
- ec2_private_dns_show_ip=True
- api_paste_config=/etc/nova/api-paste.ini
- volumes_path=/var/lib/nova/volumes
- enabled_apis=ec2,osapi_compute,metadata
-
- rpc_backend = rabbit
- rabbit_host = 10.0.0.11
- my_ip = 10.0.0.11
- vncserver_listen = 10.0.0.11
- vncserver_proxyclient_address = 10.0.0.11
- auth_strategy = keystone
-
- [keystone_authtoken]
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = nova
- admin_password = service_pass
-
- [database]
- connection = mysql://nova:NOVA_DBPASS@10.0.0.11/nova
复制代码
删除sqlite数据库
- rm /var/lib/nova/nova.sqlite
复制代码
初始化nova数据库
复制代码
重启nova相关服务
- service nova-api restart
- service nova-cert restart
- service nova-conductor restart
- service nova-consoleauth restart
- service nova-novncproxy restart
- service nova-scheduler restart
复制代码
检查
- # nova-manage service list
- Binary Host Zone Status State Updated_At
- nova-cert controller internal enabled :-) 2014-08-26 14:13:08
- nova-consoleauth controller internal enabled :-) 2014-08-26 14:13:08
- nova-conductor controller internal enabled :-) 2014-08-26 14:13:08
- nova-scheduler controller internal enabled :-) 2014-08-26 14:13:08
复制代码
Neutron控制节点,也是需要安装Neutron server
- apt-get install -y neutron-server neutron-plugin-ml2
复制代码
创建Neutron数据库 mysql –u root –p
- CREATE DATABASE neutron;
- GRANT ALL PRIVILEGES ON neutron.* TO neutron@'localhost' IDENTIFIED BY 'NEUTRON_DBPASS';
- GRANT ALL PRIVILEGES ON neutron.* TO neutron@'%' IDENTIFIED BY 'NEUTRON_DBPASS';
-
- exit;
复制代码
keystone创建neutron用户和角色
- keystone user-create --name=neutron --pass=service_pass --email=neutron@domain.com
- keystone user-role-add --user=neutron --tenant=service --role=admin
复制代码
注册服务和endpoint
- keystone service-create --name=neutron --type=network --description="OpenStack Networking"
-
- keystone endpoint-create \
- --service-id=$(keystone service-list | awk '/ network / {print $2}') \
- --publicurl=http://192.168.100.11:9696 \
- --internalurl=http://10.0.0.11:9696 \
- --adminurl=http://10.0.0.11:9696
复制代码
编辑 /etc/neutron/neutron.conf,关键的是nova_admin_tenant_id 需要你手工用命令获得,再填写
- keystone tenant-list | awk '/ service / { print $2 }'
复制代码
- #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
- core_plugin = ml2
-
- # service_plugins =
- # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
- service_plugins = router
-
- # auth_strategy = keystone
- auth_strategy = keystone
-
- # allow_overlapping_ips = False
- allow_overlapping_ips = True
-
- rpc_backend = neutron.openstack.common.rpc.impl_kombu
-
- rabbit_host = 10.0.0.11
-
- notification_driver = neutron.openstack.common.notifier.rpc_notifier
-
- # ======== neutron nova interactions ==========
- # Send notification to nova when port status is active.
- notify_nova_on_port_status_changes = True
-
- # Send notifications to nova when port data (fixed_ips/floatingips) change
- # so nova can update it's cache.
- notify_nova_on_port_data_changes = True
-
- # URL for connection to nova (Only supports one nova region currently).
- nova_url = http://10.0.0.11:8774/v2
-
- # Name of nova region to use. Useful if keystone manages more than one region
- # nova_region_name =
-
- # Username for connection to nova in admin context
- nova_admin_username = nova
-
- # The uuid of the admin nova tenant
- nova_admin_tenant_id = cb45c886bc094f65940ba29d79eab8aa
-
- # Password for connection to nova in admin context.
- nova_admin_password = service_pass
-
- # Authorization URL for connection to nova in admin context.
- nova_admin_auth_url = http://10.0.0.11:35357/v2.0
-
- [keystone_authtoken]
- #auth_host = 127.0.0.1
- #auth_port = 35357
- #auth_protocol = http
- #admin_tenant_name = %SERVICE_TENANT_NAME%
- #admin_user = %SERVICE_USER%
- #admin_password = %SERVICE_PASSWORD%
- #signing_dir = $state_path/keystone-signing
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = neutron
- admin_password = service_pass
-
- [database]
- # This line MUST be changed to actually run the plugin.
- # Example:
- # connection = mysql://root:pass@127.0.0.1:3306/neutron
- # Replace 127.0.0.1 above with the IP address of the database used by the
- # main neutron server. (Leave it as is if the database runs on this host.)
- #connection = sqlite:////var/lib/neutron/neutron.sqlite
- connection = mysql://neutron:NEUTRON_DBPASS@10.0.0.11/neutron
复制代码
编辑 /etc/neutron/plugins/ml2/ml2_conf.ini
- [ml2]
- type_drivers = gre
- tenant_network_types = gre
- mechanism_drivers = openvswitch
-
- [ml2_type_gre]
- tunnel_id_ranges = 1:1000
-
- [securitygroup]
- firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
- enable_security_group = True
复制代码
编辑/etc/nova/nova.conf, 让nova支持neutron,在[DEFAULT] 添加
- network_api_class=nova.network.neutronv2.api.API
- neutron_url=http://10.0.0.11:9696
- neutron_auth_strategy=keystone
- neutron_admin_tenant_name=service
- neutron_admin_username=neutron
- neutron_admin_password=service_pass
- neutron_admin_auth_url=http://10.0.0.11:35357/v2.0
- libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver
- linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver
- firewall_driver=nova.virt.firewall.NoopFirewallDriver
- security_group_api=neutron
复制代码
重启nova服务
- service nova-api restart
- service nova-scheduler restart
- service nova-conductor restart
复制代码
重启neutron服务
- service neutron-server restart
复制代码
查看log
- root@controller:~# tail -f /var/log/neutron/*
- 2014-09-02 07:27:53.950 5373 WARNING neutron.api.extensions [-] Extension fwaas not supported by any of loaded plugins
- 2014-09-02 07:27:53.952 5373 WARNING neutron.api.extensions [-] Extension flavor not supported by any of loaded plugins
- 2014-09-02 07:27:53.962 5373 WARNING neutron.api.extensions [-] Extension lbaas_agent_scheduler not supported by any of loaded plugins
- 2014-09-02 07:27:53.967 5373 WARNING neutron.api.extensions [-] Extension lbaas not supported by any of loaded plugins
- 2014-09-02 07:27:53.969 5373 WARNING neutron.api.extensions [-] Extension metering not supported by any of loaded plugins
- 2014-09-02 07:27:53.973 5373 WARNING neutron.api.extensions [-] Extension port-security not supported by any of loaded plugins
- 2014-09-02 07:27:53.977 5373 WARNING neutron.api.extensions [-] Extension routed-service-insertion not supported by any of loaded plugins
复制代码
日志里显示找不到插件,这都是正常的。
HorizonDashboard的安装,倒是比较简单,不需要创建数据库。
- apt-get install -y apache2 memcached libapache2-mod-wsgi openstack-dashboard
复制代码
编辑 /etc/openstack-dashboard/local_settings.py
- #ALLOWED_HOSTS = ['horizon.example.com', ]
- ALLOWED_HOSTS = ['localhost','192.168.100.11']
-
- #OPENSTACK_HOST = "127.0.0.1"
- OPENSTACK_HOST = "10.0.0.11"
复制代码
重启apache服务
- service apache2 restart; service memcached restart
复制代码
看到登录界面,应该是无法登录。
安装Openstack client端
在控制节点装上Openstack的client端,这样会方便很多,很多Neutron的操作,你都可以进行
- apt-get -y install python-openstackclient
复制代码
网络节点看图理解的更好,这图来自redhat的官方文档。
网络节点需要3块网卡。经常有朋友问,1块网卡是否可以。其实1块网卡肯定也是可以的,不过不利于大家理解。不过大家都很难找到3块网卡的机器,所以在IaaS下来测试,就方便很多。
创建一个虚拟机,名字为:network, 删除网卡,并且添加3块网卡。ssh到虚拟机上,默认是无法访问外网的,原因也很简单,没有默认路由,手工添加默认路由就可以。
由于网络节点,比较特殊,我们需要把网卡的Ip设置成固定 /etc/netwrok/interface
- # This file describes the network interfaces available on your system
- # and how to activate them. For more information, see interfaces(5).
-
- # The loopback network interface
- auto lo
- iface lo inet loopback
-
- # Source interfaces
- # Please check /etc/network/interfaces.d before changing this file
- # as interfaces may have been defined in /etc/network/interfaces.d
- # NOTE: the primary ethernet device is defined in
- # /etc/network/interfaces.d/eth0
- # See LP: #1262951
- #source /etc/network/interfaces.d/*.cfg
- # The management network interface
- auto eth0
- iface eth0 inet static
- address 10.0.0.21
- netmask 255.255.255.0
-
- # VM traffic interface
- auto eth1
- iface eth1 inet static
- address 10.0.1.21
- netmask 255.255.255.0
-
- # The public network interface
- auto eth2
- iface eth2 inet static
- address 192.168.100.21
- netmask 255.255.255.0
- gateway 192.168.100.1
- dns-nameservers 114.114.114.114
复制代码
设置完毕,重启虚拟机。
这个时候,你就可以访问外网,安装包。
- apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码
同步时间
复制代码
编辑 /etc/ntp.conf
复制代码
重启NTP服务
复制代码
安装基础组件
- apt-get install -y vlan bridge-utils
复制代码
编辑 /etc/sysctl.conf
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.default.rp_filter=0
复制代码
检测
复制代码
安装Neutron组件
- apt-get install -y neutron-plugin-ml2 neutron-plugin-openvswitch-agent \
- dnsmasq neutron-l3-agent neutron-dhcp-agent
复制代码
编辑 /etc/neutron/neutron.conf , 这里修改的内容,比控制节点少很多。
- #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
- core_plugin = ml2
-
- # service_plugins =
- # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
- service_plugins = router
-
- # The strategy to be used for auth.
- # Supported values are 'keystone'(default), 'noauth'.
- auth_strategy = keystone
-
- allow_overlapping_ips = True
-
- rpc_backend = neutron.openstack.common.rpc.impl_kombu
-
- rabbit_host = 10.0.0.11
-
- [keystone_authtoken]
- #auth_host = 127.0.0.1
- #auth_port = 35357
- #auth_protocol = http
- #admin_tenant_name = %SERVICE_TENANT_NAME%
- #admin_user = %SERVICE_USER%
- #admin_password = %SERVICE_PASSWORD%
- #signing_dir = $state_path/keystone-signing
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = neutron
- admin_password = service_pass
复制代码
编辑 /etc/neutron/l3_agent.ini
- interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
- use_namespaces = True
复制代码
编辑 /etc/neutron/dhcp_agent.ini
- interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
- dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
- use_namespaces = True
复制代码
编辑 /etc/neutron/metadata_agent.ini
- auth_url = http://10.0.0.11:5000/v2.0
- auth_region = regionOne
-
- admin_tenant_name = service
- admin_user = neutron
- admin_password = service_pass
- nova_metadata_ip = 10.0.0.11
- metadata_proxy_shared_secret = helloOpenStack
复制代码
登录控制节点,修改 /etc/nova.conf 在[DEFAULT] 加入下面内容
- service_neutron_metadata_proxy = true
- neutron_metadata_proxy_shared_secret = helloOpenStack
复制代码
重启nova api服务
复制代码
编辑 /etc/neutron/plugins/ml2/ml2_conf.ini
- [ml2]
- type_drivers = gre
- tenant_network_types = gre
- mechanism_drivers = openvswitch
-
- [ml2_type_gre]
- tunnel_id_ranges = 1:1000
-
- [ovs]
- local_ip = 10.0.1.21
- tunnel_type = gre
- enable_tunneling = True
-
- [securitygroup]
- firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
- enable_security_group = True
复制代码
重启openvswitch
- service openvswitch-switch restart
复制代码
创建br-ex
创建br-ex连接外网,这个不太好理解,看图
大概意思是:我们创建一个bridge br-ex,把br-ex绑定在eth2下,eth2是连接到公网的路由器上的。
- ovs-vsctl add-br br-ex
- ovs-vsctl add-port br-ex eth2
复制代码
下面内容是我操作的结果,大家慢慢理解.
编辑 /etc/network/interfaces
- # This file describes the network interfaces available on your system
- # and how to activate them. For more information, see interfaces(5).
-
- # The loopback network interface
- auto lo
- iface lo inet loopback
-
- # Source interfaces
- # Please check /etc/network/interfaces.d before changing this file
- # as interfaces may have been defined in /etc/network/interfaces.d
- # NOTE: the primary ethernet device is defined in
- # /etc/network/interfaces.d/eth0
- # See LP: #1262951
- #source /etc/network/interfaces.d/*.cfg
- # The management network interface
- auto eth0
- iface eth0 inet static
- address 10.0.0.21
- netmask 255.255.255.0
-
- # VM traffic interface
- auto eth1
- iface eth1 inet static
- address 10.0.1.21
- netmask 255.255.255.0
-
- # The public network interface
- # auto eth2
- # iface eth2 inet static
- # address 192.168.100.21
- # netmask 255.255.255.0
- # gateway 192.168.100.1
- # dns-nameservers 114.114.114.114
-
- auto eth2
- iface eth2 inet manual
- up ifconfig $IFACE 0.0.0.0 up
- up ip link set $IFACE promisc on
- down ip link set $IFACE promisc off
- down ifconfig $IFACE down
-
- auto br-ex
- iface br-ex inet static
- address 192.168.100.21
- netmask 255.255.255.0
- gateway 192.168.100.1
- dns-nameservers 114.114.114.114
复制代码
重启虚拟机
替换br-ex和eth2的mac地址
由于网络的限制,目前192.168.100.21和192.168.100.11是无法通讯的,原因是因为出于安全的考虑,对网络访问的mac地址和ip地址做了绑定和限制。
通过ifconfig 查看网卡的mac地址,通过命令,把mac地址互换。
- br-ex mac 地址 c2:32:7d:cf:9d:4
- eth2 mac地址 fa:16:3e:80:5d:e6
- ip link set eth2 addr c2:32:7d:cf:9d:43
- ip link set br-ex addr fa:16:3e:80:5d:e6
复制代码
这个时候,外部网络的IP就可以互相访问。这些修改是临时性的,如果重启neutron服务,mac地址就会恢复。不过我们实验不需要重启服务。这里提供的是临时的方法,后面有彻底解决问题的办法。
设置环境变量
- cat <<EOF >>/root/creds
- export OS_TENANT_NAME=admin
- export OS_USERNAME=admin
- export OS_PASSWORD=admin_pass
- export OS_AUTH_URL="http://192.168.100.11:5000/v2.0/"
- EOF
复制代码
这样你就可以看到安装的agent
- source creds
- neutron agent-list
复制代码
计算节点
创建一个虚拟机,名字为:compute1, 删除网卡,并且添加2块网卡。ssh到虚拟机上.
计算节点默认是不需要接公网,不过由于我需要安装包,必须联网,所以你可以创建完虚拟机后,给虚拟机连接到外部网络,装完系统后,再断开就可以。
- route add default gw 192.168.100.1
复制代码
这个时候,你就可以访问外网,安装包。
- apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码
同步时间
- apt-get install -y kvm libvirt-bin pm-utils
复制代码
安装计算节点组件
- apt-get install -y nova-compute-kvm python-guestfs
复制代码
让内核只读
- dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-$(uname -r)
复制代码
创建脚本 /etc/kernel/postinst.d/statoverride
- #!/bin/sh
- version="$1"
- # passing the kernel version is required
- [ -z "${version}" ] && exit 0
- dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-${version}
复制代码
允许运行
- chmod +x /etc/kernel/postinst.d/statoverride
复制代码
编辑 /etc/nova/nova.conf 文件,添加下面内容
- [DEFAULT]
- dhcpbridge_flagfile=/etc/nova/nova.conf
- dhcpbridge=/usr/bin/nova-dhcpbridge
- logdir=/var/log/nova
- state_path=/var/lib/nova
- lock_path=/var/lock/nova
- force_dhcp_release=True
- iscsi_helper=tgtadm
- libvirt_use_virtio_for_bridges=True
- connection_type=libvirt
- root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
- verbose=True
- ec2_private_dns_show_ip=True
- api_paste_config=/etc/nova/api-paste.ini
- volumes_path=/var/lib/nova/volumes
- enabled_apis=ec2,osapi_compute,metadata
-
- auth_strategy = keystone
- rpc_backend = rabbit
- rabbit_host = 10.0.0.11
- my_ip = 10.0.0.31
- vnc_enabled = True
- vncserver_listen = 0.0.0.0
- vncserver_proxyclient_address = 10.0.0.31
- novncproxy_base_url = http://192.168.100.11:6080/vnc_auto.html
- glance_host = 10.0.0.11
- vif_plugging_is_fatal=false
- vif_plugging_timeout=0
-
-
- [database]
- connection = mysql://nova:NOVA_DBPASS@10.0.0.11/nova
-
- [keystone_authtoken]
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = nova
- admin_password = service_pass
复制代码
删除sqlite
- rm /var/lib/nova/nova.sqlite
复制代码
重启compute服务
- service nova-compute restart
复制代码
编辑 /etc/sysctl.conf
- net.ipv4.ip_forward=1
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.default.rp_filter=0
复制代码
马上生效
- apt-get install -y neutron-common neutron-plugin-ml2 neutron-plugin-openvswitch-agent
复制代码
编辑 /etc/neutron/neutron.conf
- #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
- core_plugin = ml2
-
- # service_plugins =
- # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
- service_plugins = router
-
- auth_strategy = keystone
-
- allow_overlapping_ips = True
-
- rpc_backend = neutron.openstack.common.rpc.impl_kombu
-
- rabbit_host = 10.0.0.11
-
- [keystone_authtoken]
- #auth_host = 127.0.0.1
- #auth_port = 35357
- #auth_protocol = http
- #admin_tenant_name = %SERVICE_TENANT_NAME%
- #admin_user = %SERVICE_USER%
- #admin_password = %SERVICE_PASSWORD%
- #signing_dir = $state_path/keystone-signing
- auth_uri = http://10.0.0.11:5000
- auth_host = 10.0.0.11
- auth_port = 35357
- auth_protocol = http
- admin_tenant_name = service
- admin_user = neutron
- admin_password = service_pass
复制代码
编辑 /etc/neutron/plugins/ml2/ml2_conf.ini
- [ml2]
- type_drivers = gre
- tenant_network_types = gre
- mechanism_drivers = openvswitch
-
- [ml2_type_gre]
- tunnel_id_ranges = 1:1000
-
- [ovs]
- local_ip = 10.0.1.31
- tunnel_type = gre
- enable_tunneling = True
-
- [securitygroup]
- firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
- enable_security_group = True
复制代码
重启OVS
- service openvswitch-switch restart
复制代码
再编辑 /etc/nova/nova.conf ,在[DEFAULT]里添加下面
- network_api_class = nova.network.neutronv2.api.API
- neutron_url = http://10.0.0.11:9696
- neutron_auth_strategy = keystone
- neutron_admin_tenant_name = service
- neutron_admin_username = neutron
- neutron_admin_password = service_pass
- neutron_admin_auth_url = http://10.0.0.11:35357/v2.0
- linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
- firewall_driver = nova.virt.firewall.NoopFirewallDriver
- security_group_api = neutron
复制代码
编辑 /etc/nova/nova-compute.conf ,修改为使用qemu
- [DEFAULT]
- compute_driver=libvirt.LibvirtDriver
- [libvirt]
- virt_type=qemu
复制代码
重启相关服务
- service nova-compute restart
- service neutron-plugin-openvswitch-agent restart
复制代码
安装就全部完成。
登录控制节点
命令行创建虚拟机在控制节点上,运行下面的命令就可以。镜像我上面已经上传。下面的操作,你完全可以在Dashboard里进行操作,这里命令行下,了解更加深入。
下面的操作,在控制节点完成。
创建外部网络
- source creds
-
- #Create the external network:
- neutron net-create ext-net --shared --router:external=True
-
- #Create the subnet for the external network:
- neutron subnet-create ext-net --name ext-subnet \
- --allocation-pool start=192.168.100.101,end=192.168.100.200 \
- --disable-dhcp --gateway 192.168.100.1 192.168.100.0/24
复制代码
给租户创建内部网络
- #Create the internal network:
- neutron net-create int-net
-
- #Create the subnet for the internal network:
- neutron subnet-create int-net --name int-subnet \
- --dns-nameserver 114.114.114.114 --gateway 172.16.1.1 172.16.1.0/24
复制代码
创建路由,并且连接到外部网络
- #Create the router:
- neutron router-create router1
-
- #Attach the router to the internal subnet:
- neutron router-interface-add router1 int-subnet
-
- #Attach the router to the external network by setting it as the gateway:
- neutron router-gateway-set router1 ext-net
复制代码
创建密钥
- nova keypair-add --pub-key ~/.ssh/id_rsa.pub key1
复制代码
设置安全组
- # Permit ICMP (ping):
- nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
-
- # Permit secure shell (SSH) access:
- nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
复制代码
创建虚拟机
- NET_ID=$(neutron net-list | awk '/ int-net / { print $2 }')
- nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic net-id=$NET_ID \
- --security-group default --key-name key1 instance1
复制代码
查看虚拟机
- neutron floatingip-create ext-net
复制代码
关联floating IP
- nova floating-ip-associate instance1 192.168.100.102
复制代码
这个时候,你会发现你在控制节点上,根本是无法访问 router 192.168.100.101和floating ip 192.168.100.102。
访问虚拟机,你需要登录网络节点上,你可以用下面命令访问虚拟机
- # ip netns
- qdhcp-bf7f3043-d696-4735-9bc7-8c2e4d95c8d5
- qrouter-7e8bbb53-1ea6-4763-a69c-a0c875b5224b
复制代码
第一个的虚拟机,第二个是路由器
- # ip netns exec qdhcp-bf7f3043-d696-4735-9bc7-8c2e4d95c8d5 ifconfig
- lo Link encap:Local Loopback
- inet addr:127.0.0.1 Mask:255.0.0.0
- inet6 addr: ::1/128 Scope:Host
- UP LOOPBACK RUNNING MTU:65536 Metric:1
- RX packets:16 errors:0 dropped:0 overruns:0 frame:0
- TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:1216 (1.2 KB) TX bytes:1216 (1.2 KB)
-
- tap1a85db16-da Link encap:Ethernet HWaddr fa:16:3e:ce:e0:e2
- inet addr:172.16.1.3 Bcast:172.16.1.255 Mask:255.255.255.0
- inet6 addr: fe80::f816:3eff:fece:e0e2/64 Scope:Link
- UP BROADCAST RUNNING MTU:1500 Metric:1
- RX packets:415 errors:0 dropped:0 overruns:0 frame:0
- TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:64724 (64.7 KB) TX bytes:10228 (10.2 KB)
复制代码
访问公网你可能发现一个很明显的问题,你在网络节点是可以ping 通虚拟机的floating IP,router的IP,不过你在控制节点是无法访问的。
如果希望比较完美,实现虚拟机可以ping通公网,那么需要我们多了解一下内容才行。可以发现全部的流量都是通过192.168.100.21这个端口出去,我们需要设置一下这个端口,运行所有的IP和mac地址通过。
登录网络节点,通过ping 192.168.100.101 和192.168.100.102 ,获得他们的mac地址。
- # arp -a
- ? (10.0.0.11) at fa:16:3e:34:d0:7a [ether] on eth0
- ? (192.168.100.102) at fa:16:3e:0c:be:cd [ether] on br-ex
- ? (10.0.1.31) at fa:16:3e:eb:96:1c [ether] on eth1
- ? (192.168.100.101) at fa:16:3e:0c:be:cd [ether] on br-ex
- ? (192.168.100.1) at fa:16:3e:c2:a8:a8 [ether] on br-ex
复制代码
下面的操作,你可以在控制节点完成
通过curl获取token
使用token,修改192.168.100.21 port 的allow_address_pairs ,可以顺便把eth2和br-ex也修改,这样就不担心重启服务。
详细的操作,就参考这篇文档就可以。
vnc访问如果你登录Horizon,访问虚拟机,vnc可能无法访问,你需要登录uos,修改安全组规则。默认第一个虚拟机使用vnc的端口是6080。或者你全部打开端口。
参考资料
ovs-vsctl操作
- root@network:~# ovs-vsctl show
- 533105dd-bd0d-4af1-a331-c9394fbcb775
- Bridge br-int
- fail_mode: secure
- Port br-int
- Interface br-int
- type: internal
- ovs_version: "2.0.2"
- root@network:~# ovs-vsctl add-br br-ex
- root@network:~# ovs-vsctl show
- 533105dd-bd0d-4af1-a331-c9394fbcb775
- Bridge br-ex
- Port br-ex
- Interface br-ex
- type: internal
- Bridge br-int
- fail_mode: secure
- Port br-int
- Interface br-int
- type: internal
- ovs_version: "2.0.2"
- root@network:~# ovs-vsctl add-port br-ex eth2
- root@network:~# ovs-vsctl show
- 533105dd-bd0d-4af1-a331-c9394fbcb775
- Bridge br-ex
- Port "eth2"
- Interface "eth2"
- Port br-ex
- Interface br-ex
- type: internal
- Bridge br-int
- fail_mode: secure
- Port br-int
- Interface br-int
- type: internal
- ovs_version: "2.0.2"
复制代码
网络节点重启服务
- service neutron-plugin-openvswitch-agent restart
- service neutron-dhcp-agent restart
- service neutron-l3-agent restart
- service neutron-metadata-agent restart
- service dnsmasq restart
复制代码
转自陈沙克