分享

UnitedStack下安装多节点OpenStack

desehawk 发表于 2014-9-17 16:43:28 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 0 12935
本帖最后由 desehawk 于 2014-9-17 16:56 编辑
问题导读



  • 如何搭建一套完整的Openstack?
  • 如何基于Neutron创建虚拟机?
  • 虚拟机如何配置访问公网?
  • Horizon的功能如何实现迁移?





搞IaaS的,有一点是比较讽刺的,开发,测试都是用硬件,并且也饱受设备的痛苦。我们本来是为了帮助用户解决使用资源的各种问题,结果我们自己还饱受折磨。
这个问题其实由来已久。2007年的时候,我当时测试ESX3.0,其实这个东西真没多复杂,就是需要硬件,当年vmware workstation根本就不支持。当年的ESX的培训,都去美国实验室,够恶心了吧。后来解决了worstation安装ESX的问题后,vmware的ESX就真正在企业普及起来。普及的速度真的很快啊。
今天Openstack非常热,Openstack要很好推广,那么培训就是必要的。只有培训推广的好,企业才能有信心去使用Openstack。能不能用Openstack培训Openstack,真的很关键。
UnitedStack团队推出了共有云,UOS,这下子有机会大家都有一个相同的环境。说实话,以前所谓测试IaaS,基本都是点击几下,没真正变成用户,没真正帮助我解决问题。我希望日后可以用这个Openstack下培训Openstack,让大家能认识到IaaS,其实有很多好玩的玩法,可以帮助你改变以前很多无法解决的问题。当然需要大家一起想想。
我之所以那么关注培训,其实是因为我自己的IT的技能很大部分都是通过参加IT培训获得的,所以也算是比较了解这个行业。
我已经把所有安装的配置文件放到github下,大家安装过程,如有一位,那么就直接参考一下
我希望任何人,都可以利用UOS,重复我文档的所有操作,可以实现下面的目标
  • 搭建一套完整的Openstack
  • 基于Neutron创建虚拟机
  • 虚拟机可以访问公网
  • Horizon的功能都可以正常使用,包括迁移
看看UOS生成的网络拓扑图,应该可以改的更加好看,大家多去给他们提提意见。

4.png



内容:
1 基本信息
2 UOS网络
3 控制节点
3.1 基础组件
3.1.1 升级内核
3.1.2 MySQL
3.1.3 消息队列RabbitMQ
3.2 keystone
3.3 Glance
3.4 Nova
3.5 Neutron
3.6 Horizon
4 网络节点
5 计算节点
6 命令行创建虚拟机
7 访问公网

7.1 vnc访问
基本信息
5.jpg



管理网络(10.0.0.0/24)
虚拟机通讯网络(10.0.1.0/24)
外部网络(192.168.100.0/24)
控制节点
eth0(10.0.0.11)

eth1
(192.168.100.11)
网络节点
eth0(10.0.0.21)
eth1(10.0.1.21)
eth2(192.168.100.21)
计算节点
eth0(10.0.0.31)
eth1(10.0.1.21)




文档很清楚,
  • 网络节点,需要3块网卡。
  • 控制节点和网络节点,需要外部网络,就是需要所谓的公网的IP
  • 计算节点是不需要公网IP
  • 所有的虚拟机访问公网,都是需要经过网络节点。
  • 192.168.100.0,就相当于公网的IP地址段


UOS网络
其实最麻烦的就是网络,把网络准备好后,那么剩下就是对着文档copy和粘贴。
  • 创建一个路由: router
  • 创建一个Openstack安全组,后面的3个虚拟机都是使用这个安全组,避免日后互相影响。
  • 申请一个公网的IP,1M带就足够,绑定路由器
  • 在网络里创建3个网络:外部网络,虚拟机通讯网络,管理网络,其中外部网络连接路由器
  • 创建7块网卡,给网卡设置固定IP


网络

6.png


7.png



网卡


8.png


这是UOS的一个特色,原理不复杂,不过使用的时候,会让你感觉很方便。目前UOS创建虚拟机的时候,还不能指定自己创建的网卡。只能是创建完成后,你删掉以前的网卡,添加自己定制的网络。

安全组

9.png


创建虚拟机

我们需要创建3台虚拟机,为了方便,虚拟机的名字,都是固定的。
  • controller
  • network
  • compute1


10.png


我采用密钥登录


11.png


目前还不支持创建虚拟机的时候,选择自己创建的网卡,只能创建完成后,把网卡删除掉,添加自己需要的网卡


12.png


添加网卡


13.png


看看添加完毕的效果

14.png


访问虚拟机
访问虚拟机有两种办法,一个就是通过路由器的端口映射,一个就是通过vpn,在我们的实验中,通过vpn的方式是最好,后面的所有操作都非常方便。

控制节点

15.jpg


上面需要的组件,已经很清楚。

基础组件升级内核
  1. apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码

时间服务器,很多问题都是由于时间不同步造成。

  1. apt-get install -y ntp
复制代码


MySQL
  1. apt-get install -y mysql-server python-mysqldb
复制代码

修改 /etc/mysql/my.cnf

  1. bind-address = 10.0.0.11
  2. [mysqld]
  3. default-storage-engine = innodb
  4. innodb_file_per_table
  5. collation-server = utf8_general_ci
  6. init-connect = 'SET NAMES utf8'
  7. character-set-server = utf8
复制代码

重启mysql

  1. service mysql restart
复制代码

安全设置

  1. mysql_install_db
  2. mysql_secure_installation
复制代码


消息队列RabbitMQ


  1. apt-get install -y rabbitmq-server
复制代码


keystone
安装keystone

  1. apt-get install -y keystone
复制代码

创建keystone数据库,都是通过 mysql –u root –p 进入

  1. CREATE DATABASE keystone;
  2. GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' IDENTIFIED BY 'KEYSTONE_DBPASS';
  3. GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' IDENTIFIED BY 'KEYSTONE_DBPASS';
  4. exit;
复制代码

删除sqllite数据库

  1. rm /var/lib/keystone/keystone.db
复制代码

编辑 /etc/keystone/keystone.conf

  1. connection = mysql://keystone:KEYSTONE_DBPASS@10.0.0.11/keystone
  2. [DEFAULT]
  3. admin_token=ADMIN
  4. log_dir=/var/log/keystone
复制代码

初始化keystone数据库

  1. service keystone restart
  2. keystone-manage db_sync
复制代码

设置环境变量

  1. export OS_SERVICE_TOKEN=ADMIN
  2. export OS_SERVICE_ENDPOINT=http://10.0.0.11:35357/v2.0
复制代码

创建管理员权力的用户

  1. keystone user-create --name=admin --pass=admin_pass --email=admin@domain.com
  2. keystone role-create --name=admin
  3. keystone tenant-create --name=admin --description="Admin Tenant"
  4. keystone user-role-add --user=admin --tenant=admin --role=admin
  5. keystone user-role-add --user=admin --role=_member_ --tenant=admin
复制代码

创建普通用户

  1. keystone user-create --name=demo --pass=demo_pass --email=demo@domain.com
  2. keystone tenant-create --name=demo --description="Demo Tenant"
  3. keystone user-role-add --user=demo --role=_member_ --tenant=demo
复制代码

创建 service 租户

  1. keystone tenant-create --name=service --description="Service Tenant"
复制代码

定义服务的API的endpoint

  1. keystone service-create --name=keystone --type=identity --description="OpenStack Identity"
复制代码

创建endpoint

  1. keystone endpoint-create \
  2. --service-id=$(keystone service-list | awk '/ identity / {print $2}') \
  3. --publicurl=http://192.168.100.11:5000/v2.0 \
  4. --internalurl=http://10.0.0.11:5000/v2.0 \
  5. --adminurl=http://10.0.0.11:35357/v2.0
复制代码


检测keystone
通过下面命令检查keystone的初始化是否正常
设置环境变量,创建creds 和 admin_creds 两个文件

  1. cat <<EOF >>/root/creds
  2. export OS_TENANT_NAME=admin
  3. export OS_USERNAME=admin
  4. export OS_PASSWORD=admin_pass
  5. export OS_AUTH_URL="http://192.168.100.11:5000/v2.0/"
  6. EOF
  7. cat <<EOF >>/root/admin_creds
  8. export OS_USERNAME=admin
  9. export OS_PASSWORD=admin_pass
  10. export OS_TENANT_NAME=admin
  11. export OS_AUTH_URL=http://10.0.0.11:35357/v2.0
  12. EOF
复制代码


检测
设置环境变量才能进行下面操作

  1. source creds
复制代码

这样就可以

  1. root@controller:~# keystone user-list
  2. +----------------------------------+-------+---------+------------------+
  3. | id | name | enabled | email |
  4. +----------------------------------+-------+---------+------------------+
  5. | 6f8bcafd62ec4e23ab2be28016829f91 | admin | True | admin@domain.com |
  6. | 66713a75b7c14f73a1c5a015241f5826 | demo | True | demo@domain.com |
  7. +----------------------------------+-------+---------+------------------+
  8. root@controller:~# keystone role-list
  9. +----------------------------------+----------+
  10. | id | name |
  11. +----------------------------------+----------+
  12. | 9fe2ff9ee4384b1894a90878d3e92bab | _member_ |
  13. | cd8dec7752d24a028f95657556f7573d | admin |
  14. +----------------------------------+----------+
  15. root@controller:~# keystone tenant-list
  16. +----------------------------------+---------+---------+
  17. | id | name | enabled |
  18. +----------------------------------+---------+---------+
  19. | efc81990ab4c433f94573e2e0fcf08c3 | admin | True |
  20. | be10dc11d4034b389bef8bbcec657f6f | demo | True |
  21. | cb45c886bc094f65940ba29d79eab8aa | service | True |
  22. +----------------------------------+---------+---------+
复制代码


查看日志
日志在/var/log/keystone/ 下,先清空日志,看看日志是否还有错误信息.

  1. echo "" > /var/log/keystone/keystone-all.log
  2. echo "" > /var/log/keystone/keystone-manage.log
  3. tail /var/log/keystone/*
复制代码


Glance
Openstack组件安装,都比较类似。

  1. apt-get install -y glance python-glanceclient
复制代码

创建数据库 mysql –u root –p

  1. CREATE DATABASE glance;
  2. GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_DBPASS';
  3. GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_DBPASS';
  4. exit;
复制代码

keystone创建glance用户和服务

  1. keystone user-create --name=glance --pass=service_pass --email=glance@domain.com
  2. keystone user-role-add --user=glance --tenant=service --role=admin
复制代码

设置endpoint

  1. keystone service-create --name=glance --type=image --description="OpenStack Image Service"
  2. keystone endpoint-create \
  3. --service-id=$(keystone service-list | awk '/ image / {print $2}') \
  4. --publicurl=http://192.168.100.11:9292 \
  5. --internalurl=http://10.0.0.11:9292 \
  6. --adminurl=http://10.0.0.11:9292
复制代码

编辑 /etc/glance/glance-api.conf

  1. [database]
  2. connection = mysql://glance:GLANCE_DBPASS@10.0.0.11/glance
  3. [DEFAULT]
  4. rpc_backend = rabbit
  5. rabbit_host = 10.0.0.11
  6. [keystone_authtoken]
  7. auth_uri = http://10.0.0.11:5000
  8. auth_host = 10.0.0.11
  9. auth_port = 35357
  10. auth_protocol = http
  11. admin_tenant_name = service
  12. admin_user = glance
  13. admin_password = service_pass
  14. [paste_deploy]
  15. flavor = keystone
复制代码

编辑 /etc/glance/glance-registry.conf

  1. [database]
  2. # The file name to use with SQLite (string value)
  3. #sqlite_db = /var/lib/glance/glance.sqlite
  4. connection = mysql://glance:GLANCE_DBPASS@10.0.0.11/glance
  5. [keystone_authtoken]
  6. auth_uri = http://10.0.0.11:5000
  7. auth_host = 10.0.0.11
  8. auth_port = 35357
  9. auth_protocol = http
  10. admin_tenant_name = service
  11. admin_user = glance
  12. admin_password = service_pass
  13. [paste_deploy]
  14. flavor = keystone
复制代码

重启服务

  1. service glance-api restart; service glance-registry restart
复制代码

初始化glance数据库

  1. glance-manage db_sync
复制代码

上传镜像

  1. source creds
  2. glance image-create --name "cirros-0.3.2-x86_64" --is-public true \
  3. --container-format bare --disk-format qcow2 \
  4. --location http://cdn.download.cirros-cloud.net/0.3.2/cirros-0.3.2-x86_64-disk.img
复制代码

查看镜像

  1. # glance image-list
  2. +--------------------------------------+---------------------+-------------+------------------+----------+--------+
  3. | ID | Name | Disk Format | Container Format | Size | Status |
  4. +--------------------------------------+---------------------+-------------+------------------+----------+--------+
  5. | d7a6d71d-4222-44f4-82d0-49c14ba19676 | cirros-0.3.2-x86_64 | qcow2 | bare | 13167616 | active |
  6. +--------------------------------------+---------------------+-------------+------------------+----------+--------+
复制代码

检测log

  1. root@controller:~# tail /var/log/glance/*
  2. ==> /var/log/glance/api.log <==
  3. 2014-09-02 07:07:12.315 2946 WARNING glance.store.base [-] Failed to configure store correctly:
  4. Store sheepdog could not be configured correctly. Reason:
  5. Error in store configuration: [Errno 2] No such file or directory Disabling add method.
  6. 2014-09-02 07:07:12.316 2946 WARNING glance.store [-] Deprecated: glance.store.
  7. sheepdog.Store not found in `known_store`.
  8. Stores need to be explicitly enabled in the configuration file.
复制代码

你会发现log里有类似的所谓错误,这个不是问题。希望glance改进一下这个地方的log。不然让很多新手很郁闷。
Nova
安装软件

  1. apt-get install -y nova-api nova-cert nova-conductor nova-consoleauth \
  2. nova-novncproxy nova-scheduler python-novaclient
复制代码

创建nova 数据库 mysql –u root –p

  1. CREATE DATABASE nova;
  2. GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'NOVA_DBPASS';
  3. GRANT ALL PRIVILEGES ON nova.* TO 'nova'@'%' IDENTIFIED BY 'NOVA_DBPASS';
  4. exit;
复制代码

配置keystone

  1. keystone user-create --name=nova --pass=service_pass --email=nova@domain.com
  2. keystone user-role-add --user=nova --tenant=service --role=admin
复制代码

设置endpoint

  1. keystone service-create --name=nova --type=compute --description="OpenStack Compute"
  2. keystone endpoint-create \
  3. --service-id=$(keystone service-list | awk '/ compute / {print $2}') \
  4. --publicurl=http://192.168.100.11:8774/v2/%\(tenant_id\)s \
  5. --internalurl=http://10.0.0.11:8774/v2/%\(tenant_id\)s \
  6. --adminurl=http://10.0.0.11:8774/v2/%\(tenant_id\)s
复制代码


编辑 /etc/nova/nova.conf
下面是我的nova.conf 文件的全部内容

  1. [DEFAULT]
  2. dhcpbridge_flagfile=/etc/nova/nova.conf
  3. dhcpbridge=/usr/bin/nova-dhcpbridge
  4. logdir=/var/log/nova
  5. state_path=/var/lib/nova
  6. lock_path=/var/lock/nova
  7. force_dhcp_release=True
  8. iscsi_helper=tgtadm
  9. libvirt_use_virtio_for_bridges=True
  10. connection_type=libvirt
  11. root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
  12. verbose=True
  13. ec2_private_dns_show_ip=True
  14. api_paste_config=/etc/nova/api-paste.ini
  15. volumes_path=/var/lib/nova/volumes
  16. enabled_apis=ec2,osapi_compute,metadata
  17. rpc_backend = rabbit
  18. rabbit_host = 10.0.0.11
  19. my_ip = 10.0.0.11
  20. vncserver_listen = 10.0.0.11
  21. vncserver_proxyclient_address = 10.0.0.11
  22. auth_strategy = keystone
  23. [keystone_authtoken]
  24. auth_uri = http://10.0.0.11:5000
  25. auth_host = 10.0.0.11
  26. auth_port = 35357
  27. auth_protocol = http
  28. admin_tenant_name = service
  29. admin_user = nova
  30. admin_password = service_pass
  31. [database]
  32. connection = mysql://nova:NOVA_DBPASS@10.0.0.11/nova
复制代码

删除sqlite数据库

  1. rm /var/lib/nova/nova.sqlite
复制代码

初始化nova数据库

  1. nova-manage db sync
复制代码

重启nova相关服务

  1. service nova-api restart
  2. service nova-cert restart
  3. service nova-conductor restart
  4. service nova-consoleauth restart
  5. service nova-novncproxy restart
  6. service nova-scheduler restart
复制代码

检查

  1. # nova-manage service list
  2. Binary                            Host     Zone          Status       State        Updated_At
  3. nova-cert                    controller internal        enabled      :-)          2014-08-26 14:13:08
  4. nova-consoleauth        controller internal         enabled      :-)          2014-08-26 14:13:08
  5. nova-conductor           controller internal         enabled      :-)          2014-08-26 14:13:08
  6. nova-scheduler            controller internal         enabled      :-)          2014-08-26 14:13:08
复制代码


Neutron
控制节点,也是需要安装Neutron server

  1. apt-get install -y neutron-server neutron-plugin-ml2
复制代码

创建Neutron数据库 mysql –u root –p

  1. CREATE DATABASE neutron;
  2. GRANT ALL PRIVILEGES ON neutron.* TO neutron@'localhost' IDENTIFIED BY 'NEUTRON_DBPASS';
  3. GRANT ALL PRIVILEGES ON neutron.* TO neutron@'%' IDENTIFIED BY 'NEUTRON_DBPASS';
  4. exit;
复制代码

keystone创建neutron用户和角色

  1. keystone user-create --name=neutron --pass=service_pass --email=neutron@domain.com
  2. keystone user-role-add --user=neutron --tenant=service --role=admin
复制代码

注册服务和endpoint

  1. keystone service-create --name=neutron --type=network --description="OpenStack Networking"
  2. keystone endpoint-create \
  3. --service-id=$(keystone service-list | awk '/ network / {print $2}') \
  4. --publicurl=http://192.168.100.11:9696 \
  5. --internalurl=http://10.0.0.11:9696 \
  6. --adminurl=http://10.0.0.11:9696
复制代码

编辑 /etc/neutron/neutron.conf,关键的是nova_admin_tenant_id 需要你手工用命令获得,再填写

  1. keystone tenant-list | awk '/ service / { print $2 }'
复制代码
  1. #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
  2. core_plugin = ml2
  3. # service_plugins =
  4. # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
  5. service_plugins = router
  6. # auth_strategy = keystone
  7. auth_strategy = keystone
  8. # allow_overlapping_ips = False
  9. allow_overlapping_ips = True
  10. rpc_backend = neutron.openstack.common.rpc.impl_kombu
  11. rabbit_host = 10.0.0.11
  12. notification_driver = neutron.openstack.common.notifier.rpc_notifier
  13. # ======== neutron nova interactions ==========
  14. # Send notification to nova when port status is active.
  15. notify_nova_on_port_status_changes = True
  16. # Send notifications to nova when port data (fixed_ips/floatingips) change
  17. # so nova can update it's cache.
  18. notify_nova_on_port_data_changes = True
  19. # URL for connection to nova (Only supports one nova region currently).
  20. nova_url = http://10.0.0.11:8774/v2
  21. # Name of nova region to use. Useful if keystone manages more than one region
  22. # nova_region_name =
  23. # Username for connection to nova in admin context
  24. nova_admin_username = nova
  25. # The uuid of the admin nova tenant
  26. nova_admin_tenant_id = cb45c886bc094f65940ba29d79eab8aa
  27. # Password for connection to nova in admin context.
  28. nova_admin_password = service_pass
  29. # Authorization URL for connection to nova in admin context.
  30. nova_admin_auth_url = http://10.0.0.11:35357/v2.0
  31. [keystone_authtoken]
  32. #auth_host = 127.0.0.1
  33. #auth_port = 35357
  34. #auth_protocol = http
  35. #admin_tenant_name = %SERVICE_TENANT_NAME%
  36. #admin_user = %SERVICE_USER%
  37. #admin_password = %SERVICE_PASSWORD%
  38. #signing_dir = $state_path/keystone-signing
  39. auth_uri = http://10.0.0.11:5000
  40. auth_host = 10.0.0.11
  41. auth_port = 35357
  42. auth_protocol = http
  43. admin_tenant_name = service
  44. admin_user = neutron
  45. admin_password = service_pass
  46. [database]
  47. # This line MUST be changed to actually run the plugin.
  48. # Example:
  49. # connection = mysql://root:pass@127.0.0.1:3306/neutron
  50. # Replace 127.0.0.1 above with the IP address of the database used by the
  51. # main neutron server. (Leave it as is if the database runs on this host.)
  52. #connection = sqlite:////var/lib/neutron/neutron.sqlite
  53. connection = mysql://neutron:NEUTRON_DBPASS@10.0.0.11/neutron
复制代码

编辑 /etc/neutron/plugins/ml2/ml2_conf.ini

  1. [ml2]
  2. type_drivers = gre
  3. tenant_network_types = gre
  4. mechanism_drivers = openvswitch
  5. [ml2_type_gre]
  6. tunnel_id_ranges = 1:1000
  7. [securitygroup]
  8. firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
  9. enable_security_group = True
复制代码

编辑/etc/nova/nova.conf, 让nova支持neutron,在[DEFAULT] 添加



  1. network_api_class=nova.network.neutronv2.api.API
  2. neutron_url=http://10.0.0.11:9696
  3. neutron_auth_strategy=keystone
  4. neutron_admin_tenant_name=service
  5. neutron_admin_username=neutron
  6. neutron_admin_password=service_pass
  7. neutron_admin_auth_url=http://10.0.0.11:35357/v2.0
  8. libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver
  9. linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver
  10. firewall_driver=nova.virt.firewall.NoopFirewallDriver
  11. security_group_api=neutron
复制代码

重启nova服务

  1. service nova-api restart
  2. service nova-scheduler restart
  3. service nova-conductor restart
复制代码

重启neutron服务

  1. service neutron-server restart
复制代码

查看log

  1. root@controller:~# tail -f /var/log/neutron/*
  2. 2014-09-02 07:27:53.950 5373 WARNING neutron.api.extensions [-] Extension fwaas not supported by any of loaded plugins
  3. 2014-09-02 07:27:53.952 5373 WARNING neutron.api.extensions [-] Extension flavor not supported by any of loaded plugins
  4. 2014-09-02 07:27:53.962 5373 WARNING neutron.api.extensions [-] Extension lbaas_agent_scheduler not supported by any of loaded plugins
  5. 2014-09-02 07:27:53.967 5373 WARNING neutron.api.extensions [-] Extension lbaas not supported by any of loaded plugins
  6. 2014-09-02 07:27:53.969 5373 WARNING neutron.api.extensions [-] Extension metering not supported by any of loaded plugins
  7. 2014-09-02 07:27:53.973 5373 WARNING neutron.api.extensions [-] Extension port-security not supported by any of loaded plugins
  8. 2014-09-02 07:27:53.977 5373 WARNING neutron.api.extensions [-] Extension routed-service-insertion not supported by any of loaded plugins
复制代码


日志里显示找不到插件,这都是正常的。

Horizon
Dashboard的安装,倒是比较简单,不需要创建数据库。

  1. apt-get install -y apache2 memcached libapache2-mod-wsgi openstack-dashboard
复制代码

编辑 /etc/openstack-dashboard/local_settings.py

  1. #ALLOWED_HOSTS = ['horizon.example.com', ]
  2. ALLOWED_HOSTS = ['localhost','192.168.100.11']
  3. #OPENSTACK_HOST = "127.0.0.1"
  4. OPENSTACK_HOST = "10.0.0.11"
复制代码

重启apache服务

  1. service apache2 restart; service memcached restart
复制代码


这个时候,你可以通过http://192.168.100.11/horizon
看到登录界面,应该是无法登录。
安装Openstack client端
在控制节点装上Openstack的client端,这样会方便很多,很多Neutron的操作,你都可以进行

  1. apt-get -y install python-openstackclient
复制代码

网络节点
看图理解的更好,这图来自redhat的官方文档。

16.png


网络节点需要3块网卡。经常有朋友问,1块网卡是否可以。其实1块网卡肯定也是可以的,不过不利于大家理解。不过大家都很难找到3块网卡的机器,所以在IaaS下来测试,就方便很多。


17.jpg


创建一个虚拟机,名字为:network, 删除网卡,并且添加3块网卡。ssh到虚拟机上,默认是无法访问外网的,原因也很简单,没有默认路由,手工添加默认路由就可以。
由于网络节点,比较特殊,我们需要把网卡的Ip设置成固定 /etc/netwrok/interface

  1. # This file describes the network interfaces available on your system
  2. # and how to activate them. For more information, see interfaces(5).
  3. # The loopback network interface
  4. auto lo
  5. iface lo inet loopback
  6. # Source interfaces
  7. # Please check /etc/network/interfaces.d before changing this file
  8. # as interfaces may have been defined in /etc/network/interfaces.d
  9. # NOTE: the primary ethernet device is defined in
  10. # /etc/network/interfaces.d/eth0
  11. # See LP: #1262951
  12. #source /etc/network/interfaces.d/*.cfg
  13. # The management network interface
  14. auto eth0
  15. iface eth0 inet static
  16. address 10.0.0.21
  17. netmask 255.255.255.0
  18. # VM traffic interface
  19. auto eth1
  20. iface eth1 inet static
  21. address 10.0.1.21
  22. netmask 255.255.255.0
  23. # The public network interface
  24. auto eth2
  25. iface eth2 inet static
  26. address 192.168.100.21
  27. netmask 255.255.255.0
  28. gateway 192.168.100.1
  29. dns-nameservers 114.114.114.114
复制代码


设置完毕,重启虚拟机。
这个时候,你就可以访问外网,安装包。

  1. apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码

同步时间

  1. apt-get install -y ntp
复制代码

编辑 /etc/ntp.conf

  1. server 10.0.0.11
复制代码

重启NTP服务

  1. service ntp restart
复制代码

安装基础组件

  1. apt-get install -y vlan bridge-utils
复制代码

编辑 /etc/sysctl.conf

  1. net.ipv4.ip_forward=1
  2. net.ipv4.conf.all.rp_filter=0
  3. net.ipv4.conf.default.rp_filter=0
复制代码

检测

  1. sysctl -p
复制代码

安装Neutron组件

  1. apt-get install -y neutron-plugin-ml2 neutron-plugin-openvswitch-agent \
  2. dnsmasq neutron-l3-agent neutron-dhcp-agent
复制代码

编辑 /etc/neutron/neutron.conf , 这里修改的内容,比控制节点少很多。
  1. #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
  2. core_plugin = ml2
  3. # service_plugins =
  4. # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
  5. service_plugins = router
  6. # The strategy to be used for auth.
  7. # Supported values are 'keystone'(default), 'noauth'.
  8. auth_strategy = keystone
  9. allow_overlapping_ips = True
  10. rpc_backend = neutron.openstack.common.rpc.impl_kombu
  11. rabbit_host = 10.0.0.11
  12. [keystone_authtoken]
  13. #auth_host = 127.0.0.1
  14. #auth_port = 35357
  15. #auth_protocol = http
  16. #admin_tenant_name = %SERVICE_TENANT_NAME%
  17. #admin_user = %SERVICE_USER%
  18. #admin_password = %SERVICE_PASSWORD%
  19. #signing_dir = $state_path/keystone-signing
  20. auth_uri = http://10.0.0.11:5000
  21. auth_host = 10.0.0.11
  22. auth_port = 35357
  23. auth_protocol = http
  24. admin_tenant_name = service
  25. admin_user = neutron
  26. admin_password = service_pass
复制代码

编辑 /etc/neutron/l3_agent.ini

  1. interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
  2. use_namespaces = True
复制代码

编辑 /etc/neutron/dhcp_agent.ini

  1. interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver
  2. dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
  3. use_namespaces = True
复制代码

编辑 /etc/neutron/metadata_agent.ini

  1. auth_url = http://10.0.0.11:5000/v2.0
  2. auth_region = regionOne
  3. admin_tenant_name = service
  4. admin_user = neutron
  5. admin_password = service_pass
  6. nova_metadata_ip = 10.0.0.11
  7. metadata_proxy_shared_secret = helloOpenStack
复制代码

登录控制节点,修改 /etc/nova.conf 在[DEFAULT] 加入下面内容

  1. service_neutron_metadata_proxy = true
  2. neutron_metadata_proxy_shared_secret = helloOpenStack
复制代码

重启nova api服务

  1. service nova-api restart
复制代码

编辑 /etc/neutron/plugins/ml2/ml2_conf.ini

  1. [ml2]
  2. type_drivers = gre
  3. tenant_network_types = gre
  4. mechanism_drivers = openvswitch
  5. [ml2_type_gre]
  6. tunnel_id_ranges = 1:1000
  7. [ovs]
  8. local_ip = 10.0.1.21
  9. tunnel_type = gre
  10. enable_tunneling = True
  11. [securitygroup]
  12. firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
  13. enable_security_group = True
复制代码

重启openvswitch

  1. service openvswitch-switch restart
复制代码


创建br-ex
创建br-ex连接外网,这个不太好理解,看图
大概意思是:我们创建一个bridge br-ex,把br-ex绑定在eth2下,eth2是连接到公网的路由器上的。

18.png


  1. ovs-vsctl add-br br-ex
  2. ovs-vsctl add-port br-ex eth2
复制代码

下面内容是我操作的结果,大家慢慢理解.

编辑 /etc/network/interfaces


  1. # This file describes the network interfaces available on your system
  2. # and how to activate them. For more information, see interfaces(5).
  3. # The loopback network interface
  4. auto lo
  5. iface lo inet loopback
  6. # Source interfaces
  7. # Please check /etc/network/interfaces.d before changing this file
  8. # as interfaces may have been defined in /etc/network/interfaces.d
  9. # NOTE: the primary ethernet device is defined in
  10. # /etc/network/interfaces.d/eth0
  11. # See LP: #1262951
  12. #source /etc/network/interfaces.d/*.cfg
  13. # The management network interface
  14. auto eth0
  15. iface eth0 inet static
  16. address 10.0.0.21
  17. netmask 255.255.255.0
  18. # VM traffic interface
  19. auto eth1
  20. iface eth1 inet static
  21. address 10.0.1.21
  22. netmask 255.255.255.0
  23. # The public network interface
  24. # auto eth2
  25. # iface eth2 inet static
  26. # address 192.168.100.21
  27. # netmask 255.255.255.0
  28. # gateway 192.168.100.1
  29. # dns-nameservers 114.114.114.114
  30. auto eth2
  31. iface eth2 inet manual
  32. up ifconfig $IFACE 0.0.0.0 up
  33. up ip link set $IFACE promisc on
  34. down ip link set $IFACE promisc off
  35. down ifconfig $IFACE down
  36. auto br-ex
  37. iface br-ex inet static
  38. address 192.168.100.21
  39. netmask 255.255.255.0
  40. gateway 192.168.100.1
  41. 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

  1. ip link set eth2 addr c2:32:7d:cf:9d:43
  2. ip link set br-ex addr fa:16:3e:80:5d:e6
复制代码


这个时候,外部网络的IP就可以互相访问。这些修改是临时性的,如果重启neutron服务,mac地址就会恢复。不过我们实验不需要重启服务。这里提供的是临时的方法,后面有彻底解决问题的办法。

设置环境变量

  1. cat <<EOF >>/root/creds
  2. export OS_TENANT_NAME=admin
  3. export OS_USERNAME=admin
  4. export OS_PASSWORD=admin_pass
  5. export OS_AUTH_URL="http://192.168.100.11:5000/v2.0/"
  6. EOF
复制代码

这样你就可以看到安装的agent

  1. source creds
  2. neutron agent-list
复制代码

1.png



计算节点
19.jpg

创建一个虚拟机,名字为:compute1, 删除网卡,并且添加2块网卡。ssh到虚拟机上.
计算节点默认是不需要接公网,不过由于我需要安装包,必须联网,所以你可以创建完虚拟机后,给虚拟机连接到外部网络,装完系统后,再断开就可以。
  1. route add default gw 192.168.100.1
复制代码

这个时候,你就可以访问外网,安装包。
  1. apt-get update -y && apt-get upgrade -y && apt-get dist-upgrade
复制代码

同步时间
  1. apt-get install -y ntp
复制代码

编辑 /etc/ntp.conf
  1. server 10.0.0.11
复制代码

重启NTP服务
  1. service ntp restart
复制代码

安装kvm套件
  1. apt-get install -y kvm libvirt-bin pm-utils
复制代码

安装计算节点组件
  1. apt-get install -y nova-compute-kvm python-guestfs
复制代码

让内核只读

  1. dpkg-statoverride  --update --add root root 0644 /boot/vmlinuz-$(uname -r)
复制代码

创建脚本 /etc/kernel/postinst.d/statoverride
  1. #!/bin/sh
  2. version="$1"
  3. # passing the kernel version is required
  4. [ -z "${version}" ] && exit 0
  5. dpkg-statoverride --update --add root root 0644 /boot/vmlinuz-${version}
复制代码

允许运行
  1. chmod +x /etc/kernel/postinst.d/statoverride
复制代码

编辑 /etc/nova/nova.conf 文件,添加下面内容
  1. [DEFAULT]
  2. dhcpbridge_flagfile=/etc/nova/nova.conf
  3. dhcpbridge=/usr/bin/nova-dhcpbridge
  4. logdir=/var/log/nova
  5. state_path=/var/lib/nova
  6. lock_path=/var/lock/nova
  7. force_dhcp_release=True
  8. iscsi_helper=tgtadm
  9. libvirt_use_virtio_for_bridges=True
  10. connection_type=libvirt
  11. root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf
  12. verbose=True
  13. ec2_private_dns_show_ip=True
  14. api_paste_config=/etc/nova/api-paste.ini
  15. volumes_path=/var/lib/nova/volumes
  16. enabled_apis=ec2,osapi_compute,metadata
  17. auth_strategy = keystone
  18. rpc_backend = rabbit
  19. rabbit_host = 10.0.0.11
  20. my_ip = 10.0.0.31
  21. vnc_enabled = True
  22. vncserver_listen = 0.0.0.0
  23. vncserver_proxyclient_address = 10.0.0.31
  24. novncproxy_base_url = http://192.168.100.11:6080/vnc_auto.html
  25. glance_host = 10.0.0.11
  26. vif_plugging_is_fatal=false
  27. vif_plugging_timeout=0
  28. [database]
  29. connection = mysql://nova:NOVA_DBPASS@10.0.0.11/nova
  30. [keystone_authtoken]
  31. auth_uri = http://10.0.0.11:5000
  32. auth_host = 10.0.0.11
  33. auth_port = 35357
  34. auth_protocol = http
  35. admin_tenant_name = service
  36. admin_user = nova
  37. admin_password = service_pass
复制代码

删除sqlite
  1. rm /var/lib/nova/nova.sqlite
复制代码

重启compute服务
  1. service nova-compute restart
复制代码

编辑 /etc/sysctl.conf
  1. net.ipv4.ip_forward=1
  2. net.ipv4.conf.all.rp_filter=0
  3. net.ipv4.conf.default.rp_filter=0
复制代码

马上生效
  1. sysctl -p
复制代码

安装网络组件
  1. apt-get install -y neutron-common neutron-plugin-ml2 neutron-plugin-openvswitch-agent
复制代码

编辑 /etc/neutron/neutron.conf
  1. #core_plugin = neutron.plugins.ml2.plugin.Ml2Plugin
  2. core_plugin = ml2
  3. # service_plugins =
  4. # Example: service_plugins = router,firewall,lbaas,vpnaas,metering
  5. service_plugins = router
  6. auth_strategy = keystone
  7. allow_overlapping_ips = True
  8. rpc_backend = neutron.openstack.common.rpc.impl_kombu
  9. rabbit_host = 10.0.0.11
  10. [keystone_authtoken]
  11. #auth_host = 127.0.0.1
  12. #auth_port = 35357
  13. #auth_protocol = http
  14. #admin_tenant_name = %SERVICE_TENANT_NAME%
  15. #admin_user = %SERVICE_USER%
  16. #admin_password = %SERVICE_PASSWORD%
  17. #signing_dir = $state_path/keystone-signing
  18. auth_uri = http://10.0.0.11:5000
  19. auth_host = 10.0.0.11
  20. auth_port = 35357
  21. auth_protocol = http
  22. admin_tenant_name = service
  23. admin_user = neutron
  24. admin_password = service_pass
复制代码

编辑  /etc/neutron/plugins/ml2/ml2_conf.ini
  1. [ml2]
  2. type_drivers = gre
  3. tenant_network_types = gre
  4. mechanism_drivers = openvswitch
  5. [ml2_type_gre]
  6. tunnel_id_ranges = 1:1000
  7. [ovs]
  8. local_ip = 10.0.1.31
  9. tunnel_type = gre
  10. enable_tunneling = True
  11. [securitygroup]
  12. firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
  13. enable_security_group = True
复制代码

重启OVS
  1. service openvswitch-switch restart
复制代码

再编辑 /etc/nova/nova.conf ,在[DEFAULT]里添加下面
  1. network_api_class = nova.network.neutronv2.api.API
  2. neutron_url = http://10.0.0.11:9696
  3. neutron_auth_strategy = keystone
  4. neutron_admin_tenant_name = service
  5. neutron_admin_username = neutron
  6. neutron_admin_password = service_pass
  7. neutron_admin_auth_url = http://10.0.0.11:35357/v2.0
  8. linuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver
  9. firewall_driver = nova.virt.firewall.NoopFirewallDriver
  10. security_group_api = neutron
复制代码

编辑 /etc/nova/nova-compute.conf ,修改为使用qemu
  1. [DEFAULT]
  2. compute_driver=libvirt.LibvirtDriver
  3. [libvirt]
  4. virt_type=qemu
复制代码

重启相关服务
  1. service nova-compute restart
  2. service neutron-plugin-openvswitch-agent restart
复制代码

安装就全部完成。
登录控制节点
2.png
命令行创建虚拟机
在控制节点上,运行下面的命令就可以。镜像我上面已经上传。下面的操作,你完全可以在Dashboard里进行操作,这里命令行下,了解更加深入。
下面的操作,在控制节点完成。
创建外部网络
  1. source creds
  2. #Create the external network:
  3. neutron net-create ext-net --shared --router:external=True
  4. #Create the subnet for the external network:
  5. neutron subnet-create ext-net --name ext-subnet \
  6. --allocation-pool start=192.168.100.101,end=192.168.100.200 \
  7. --disable-dhcp --gateway 192.168.100.1 192.168.100.0/24
复制代码

给租户创建内部网络
  1. #Create the internal network:
  2. neutron net-create int-net
  3. #Create the subnet for the internal network:
  4. neutron subnet-create int-net --name int-subnet \
  5. --dns-nameserver 114.114.114.114 --gateway 172.16.1.1 172.16.1.0/24
复制代码

创建路由,并且连接到外部网络
  1. #Create the router:
  2. neutron router-create router1
  3. #Attach the router to the internal subnet:
  4. neutron router-interface-add router1 int-subnet
  5. #Attach the router to the external network by setting it as the gateway:
  6. neutron router-gateway-set router1 ext-net
复制代码

创建密钥
  1. ssh-keygen
复制代码

添加公钥
  1. nova keypair-add --pub-key ~/.ssh/id_rsa.pub key1
复制代码

设置安全组
  1. # Permit ICMP (ping):
  2. nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
  3. # Permit secure shell (SSH) access:
  4. nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
复制代码

创建虚拟机
  1. NET_ID=$(neutron net-list | awk '/ int-net / { print $2 }')
  2. nova boot --flavor m1.tiny --image cirros-0.3.2-x86_64 --nic net-id=$NET_ID \
  3. --security-group default --key-name key1 instance1
复制代码

查看虚拟机
  1. nova list
复制代码

申请公网IP
  1. neutron floatingip-create ext-net
复制代码

关联floating IP
  1. nova floating-ip-associate instance1 192.168.100.102
复制代码

这个时候,你会发现你在控制节点上,根本是无法访问 router 192.168.100.101和floating ip 192.168.100.102。
访问虚拟机,你需要登录网络节点上,你可以用下面命令访问虚拟机
  1. # ip netns
  2. qdhcp-bf7f3043-d696-4735-9bc7-8c2e4d95c8d5
  3. qrouter-7e8bbb53-1ea6-4763-a69c-a0c875b5224b
复制代码

第一个的虚拟机,第二个是路由器
  1. # ip netns exec qdhcp-bf7f3043-d696-4735-9bc7-8c2e4d95c8d5 ifconfig
  2. lo        Link encap:Local Loopback  
  3.           inet addr:127.0.0.1  Mask:255.0.0.0
  4.           inet6 addr: ::1/128 Scope:Host
  5.           UP LOOPBACK RUNNING  MTU:65536  Metric:1
  6.           RX packets:16 errors:0 dropped:0 overruns:0 frame:0
  7.           TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
  8.           collisions:0 txqueuelen:0
  9.           RX bytes:1216 (1.2 KB)  TX bytes:1216 (1.2 KB)
  10. tap1a85db16-da Link encap:Ethernet  HWaddr fa:16:3e:ce:e0:e2  
  11.           inet addr:172.16.1.3  Bcast:172.16.1.255  Mask:255.255.255.0
  12.           inet6 addr: fe80::f816:3eff:fece:e0e2/64 Scope:Link
  13.           UP BROADCAST RUNNING  MTU:1500  Metric:1
  14.           RX packets:415 errors:0 dropped:0 overruns:0 frame:0
  15.           TX packets:105 errors:0 dropped:0 overruns:0 carrier:0
  16.           collisions:0 txqueuelen:0
  17.           RX bytes:64724 (64.7 KB)  TX bytes:10228 (10.2 KB)
复制代码

20.png

访问公网
你可能发现一个很明显的问题,你在网络节点是可以ping 通虚拟机的floating IP,router的IP,不过你在控制节点是无法访问的。
如果希望比较完美,实现虚拟机可以ping通公网,那么需要我们多了解一下内容才行。可以发现全部的流量都是通过192.168.100.21这个端口出去,我们需要设置一下这个端口,运行所有的IP和mac地址通过。
登录网络节点,通过ping 192.168.100.101 和192.168.100.102 ,获得他们的mac地址。
  1. # arp -a
  2. ? (10.0.0.11) at fa:16:3e:34:d0:7a [ether] on eth0
  3. ? (192.168.100.102) at fa:16:3e:0c:be:cd [ether] on br-ex
  4. ? (10.0.1.31) at fa:16:3e:eb:96:1c [ether] on eth1
  5. ? (192.168.100.101) at fa:16:3e:0c:be:cd [ether] on br-ex
  6. ? (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。或者你全部打开端口。

21.png


参考资料
ovs-vsctl操作
  1. root@network:~# ovs-vsctl show
  2. 533105dd-bd0d-4af1-a331-c9394fbcb775
  3.     Bridge br-int
  4.         fail_mode: secure
  5.         Port br-int
  6.             Interface br-int
  7.                 type: internal
  8.     ovs_version: "2.0.2"
  9. root@network:~# ovs-vsctl add-br br-ex
  10. root@network:~# ovs-vsctl show        
  11. 533105dd-bd0d-4af1-a331-c9394fbcb775
  12.     Bridge br-ex
  13.         Port br-ex
  14.             Interface br-ex
  15.                 type: internal
  16.     Bridge br-int
  17.         fail_mode: secure
  18.         Port br-int
  19.             Interface br-int
  20.                 type: internal
  21.     ovs_version: "2.0.2"
  22. root@network:~# ovs-vsctl add-port br-ex eth2
  23. root@network:~# ovs-vsctl show
  24. 533105dd-bd0d-4af1-a331-c9394fbcb775
  25.     Bridge br-ex
  26.         Port "eth2"
  27.             Interface "eth2"
  28.         Port br-ex
  29.             Interface br-ex
  30.                 type: internal
  31.     Bridge br-int
  32.         fail_mode: secure
  33.         Port br-int
  34.             Interface br-int
  35.                 type: internal
  36.     ovs_version: "2.0.2"
复制代码

网络节点重启服务
  1. service neutron-plugin-openvswitch-agent restart
  2. service neutron-dhcp-agent restart
  3. service neutron-l3-agent restart
  4. service neutron-metadata-agent restart
  5. service dnsmasq restart
复制代码






转自陈沙克

没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条