Openstack Grizzily版本已经相当完善,根据官方文档安装基本不存在什么问题,但是想快速测试了解Openstack功能的用户非常多,devstack的安装需要check最新的代码,时常碰到一些bug。这里记录一下我的单节点安装日志,尽量合并,优化一些项目以减少复杂性:
1.安装操作系统:Ubuntu12.04 LTS,打开ssh, 配置root,先更新一下apt source
2.对于12.04要加上grizzily的源:
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/grizzly main >> /etc/apt/sources.list.d/grizzly.list apt-get update apt-get install ubuntu-cloud-keyring python-software-properties software-properties-common python-keyring
3.更新系统
echo deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/grizzly main >> /etc/apt/sources.list.d/grizzly.list apt-get update apt-get install ubuntu-cloud-keyring python-software-properties software-properties-common python-keyring
这次更新比较多,重启一下是个好习惯.
reboot
4.检查语言,如果是中文系统,请改成英文,这一步是可选的了,不过根据我的经验,写上LC_ALL比不写好。
vi /etc/default/locale LANG="en_US.UTF-8" LANGUAGE="en_US:en" LC_ALL="en_US.utf8"
5.配置IP:
# The primary network interface auto eth0 iface eth0 inet static address 10.51.166.16 netmask 255.255.255.0 network 10.51.166.0 gateway 10.51.166.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 114.114.114.114 auto eth1 iface eth1 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
6.安装组件了,为了方便,一次将所有的包都装上,这里只列了一些关键包,根据依赖关系,其它的包应该都会自动装上:
apt-get install ntp mysql-server python-mysqldb python-sqlalchemy phpmyadmin rabbitmq-server keystone glance nova-novncproxy novnc nova-api nova-ajax-console-proxy nova-cert nova-conductor nova-consoleauth nova-doc nova-scheduler nova-compute-kvm cinder-api cinder-scheduler cinder-volume iscsitarget open-iscsi iscsitarget-dkms quantum-server python-quantumclient quantum-plugin-openvswitch quantum-plugin-openvswitch-agent quantum-dhcp-agent quantum-l3-agent quantum-lbaas-agent quantum-metadata-agent memcached libapache2-mod-wsgi openstack-dashboard
7. 配置本地环境变量
vi ~/novarc export OS_TENANT_NAME=admin export OS_TENANT_ID=30387eb46b624012bce5172ac77ab407 export OS_USERNAME=admin export OS_PASSWORD=password export OS_AUTH_URL="http://127.0.0.1:35357/v2.0" export OS_REGION_NAME=RegionOne export OS_IDENTITY_API_VERSION=2.0 export SERVICE_TOKEN=ADMIN export SERVICE_ENDPOINT="http://127.0.0.1:35357/v2.0" echo "source ~/novarc" >> ~/.bashrc
允许ip转发
sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
8.创建mysql数据库,一次创建所有的库,可以用http://10.51.166.16/phpmyadmin界面来创建:
keystone;glance;nova;cinder;quantum;
9.配置keystone
sed -i "s/sqlite:////var/lib/keystone/keystone.db/mysql://root:[email protected]/keystone/g" /etc/keystone/keystone.conf
restart keystone
初始化keystone数据库,创建表
keystone-manage db_sync
10.初始化keystone_db数据,创建用户和服务,这里使用一个脚本,粘到文件中运行,内容如下:
#!/bin/sh # # Keystone basic Endpoints # Mainly inspired by https://github.com/openstack/keystone/blob/master/tools/sample_data.sh # Modified by Bilel Msekni / Institut Telecom # # Support: [email protected] # License: Apache Software License (ASL) 2.0 # # Host address HOST_IP=127.0.0.1 EXT_HOST_IP=$HOST_IP ADMIN_PASSWORD=${ADMIN_PASSWORD:-password} SERVICE_PASSWORD=${SERVICE_PASSWORD:-password} export SERVICE_TOKEN="ADMIN" export SERVICE_ENDPOINT="http://${HOST_IP}:35357/v2.0" SERVICE_TENANT_NAME=${SERVICE_TENANT_NAME:-service} # MySQL definitions MYSQL_USER=root MYSQL_DATABASE=keystone MYSQL_HOST=$HOST_IP MYSQL_PASSWORD=password # Keystone definitions KEYSTONE_REGION=RegionOne #====================================== get_id () { echo `$@ | awk '/ id / { print $4 }'` } # Tenants ADMIN_TENANT=$(get_id keystone tenant-create --name=admin) SERVICE_TENANT=$(get_id keystone tenant-create --name=$SERVICE_TENANT_NAME) # Users ADMIN_USER=$(get_id keystone user-create --name=admin --pass="$ADMIN_PASSWORD" --email=[email protected]) # Roles ADMIN_ROLE=$(get_id keystone role-create --name=admin) KEYSTONEADMIN_ROLE=$(get_id keystone role-create --name=KeystoneAdmin) KEYSTONESERVICE_ROLE=$(get_id keystone role-create --name=KeystoneServiceAdmin) # Add Roles to Users in Tenants keystone user-role-add --user-id $ADMIN_USER --role-id $ADMIN_ROLE --tenant-id $ADMIN_TENANT keystone user-role-add --user-id $ADMIN_USER --role-id $KEYSTONEADMIN_ROLE --tenant-id $ADMIN_TENANT keystone user-role-add --user-id $ADMIN_USER --role-id $KEYSTONESERVICE_ROLE --tenant-id $ADMIN_TENANT # The Member role is used by Horizon and Swift MEMBER_ROLE=$(get_id keystone role-create --name=Member) # Configure service users/roles SERVICE_USER=$(get_id keystone user-create --name=service --pass="$SERVICE_PASSWORD" --tenant-id $SERVICE_TENANT --email=[email protected]) keystone user-role-add --tenant-id $SERVICE_TENANT --user-id $SERVICE_USER --role-id $ADMIN_ROLE #===========Service=========== keystone service-create --name nova --type compute --description 'OpenStack Compute Service' keystone service-create --name cinder --type volume --description 'OpenStack Volume Service' keystone service-create --name glance --type image --description 'OpenStack Image Service' keystone service-create --name keystone --type identity --description 'OpenStack Identity' keystone service-create --name ec2 --type ec2 --description 'OpenStack EC2 service' keystone service-create --name quantum --type network --description 'OpenStack Networking service' #============= while getopts "u:D:p:m:K:R:E:T:vh" opt; do case $opt in u) MYSQL_USER=$OPTARG ;; D) MYSQL_DATABASE=$OPTARG ;; p) MYSQL_PASSWORD=$OPTARG ;; m) MYSQL_HOST=$OPTARG ;; K) MASTER=$OPTARG ;; R) KEYSTONE_REGION=$OPTARG ;; E) export SERVICE_ENDPOINT=$OPTARG ;; T) export SERVICE_TOKEN=$OPTARG ;; v) set -x ;; h) cat <<EOF Usage: $0 [-m mysql_hostname] [-u mysql_username] [-D mysql_database] [-p mysql_password] [-K keystone_master ] [ -R keystone_region ] [ -E keystone_endpoint_url ] [ -T keystone_token ] Add -v for verbose mode, -h to display this message. EOF exit 0 ;; \?) echo "Unknown option -$OPTARG" >&2 exit 1 ;; :) echo "Option -$OPTARG requires an argument" >&2 exit 1 ;; esac done if [ -z "$KEYSTONE_REGION" ]; then echo "Keystone region not set. Please set with -R option or set KEYSTONE_REGION variable." >&2 missing_args="true" fi if [ -z "$SERVICE_TOKEN" ]; then echo "Keystone service token not set. Please set with -T option or set SERVICE_TOKEN variable." >&2 missing_args="true" fi if [ -z "$SERVICE_ENDPOINT" ]; then echo "Keystone service endpoint not set. Please set with -E option or set SERVICE_ENDPOINT variable." >&2 missing_args="true" fi if [ -z "$MYSQL_PASSWORD" ]; then echo "MySQL password not set. Please set with -p option or set MYSQL_PASSWORD variable." >&2 missing_args="true" fi if [ -n "$missing_args" ]; then exit 1 fi create_endpoint () { case $1 in compute) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':8774/v2/$(tenant_id)s' --adminurl 'http://'"$HOST_IP"':8774/v2/$(tenant_id)s' --internalurl 'http://'"$HOST_IP"':8774/v2/$(tenant_id)s' ;; volume) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':8776/v1/$(tenant_id)s' --adminurl 'http://'"$HOST_IP"':8776/v1/$(tenant_id)s' --internalurl 'http://'"$HOST_IP"':8776/v1/$(tenant_id)s' ;; image) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':9292/v2' --adminurl 'http://'"$HOST_IP"':9292/v2' --internalurl 'http://'"$HOST_IP"':9292/v2' ;; identity) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':5000/v2.0' --adminurl 'http://'"$HOST_IP"':35357/v2.0' --internalurl 'http://'"$HOST_IP"':5000/v2.0' ;; ec2) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':8773/services/Cloud' --adminurl 'http://'"$HOST_IP"':8773/services/Admin' --internalurl 'http://'"$HOST_IP"':8773/services/Cloud' ;; network) keystone endpoint-create --region $KEYSTONE_REGION --service-id $2 --publicurl 'http://'"$EXT_HOST_IP"':9696/' --adminurl 'http://'"$HOST_IP"':9696/' --internalurl 'http://'"$HOST_IP"':9696/' ;; esac } for i in compute volume image object-store identity ec2 network; do id=`mysql -h "$MYSQL_HOST" -u "$MYSQL_USER" -p"$MYSQL_PASSWORD" "$MYSQL_DATABASE" -ss -e "SELECT id FROM service WHERE type='"$i"';"` || exit 1 create_endpoint $i $id
脚本执行完毕,正常输出:
root@ubuntu:~# bash keystone_init.sh +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Compute Service | | id | 5612ab143e9e4c7dbd174152577014d8 | | name | nova | | type | compute | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Volume Service | | id | 5ed1d0c1e7d047bc946218f9a9046b0a | | name | cinder | | type | volume | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Image Service | | id | 93fd957882be4538871b023278e8267b | | name | glance | | type | image | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Identity | | id | 66575a5c0dbc4763bdd207e85726f5b4 | | name | keystone | | type | identity | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack EC2 service | | id | 410230c2679b4f57a7689b644559dbc9 | | name | ec2 | | type | ec2 | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | description | OpenStack Networking service | | id | 13a1cd0634da46b281a4ef5460f9379f | | name | quantum | | type | network | +-------------+----------------------------------+ +-------------+----------------------------------------+ | Property | Value | +-------------+----------------------------------------+ | adminurl | http://127.0.0.1:8774/v2/$(tenant_id)s | | id | 63b52389dc1040079b29e31c04a2ef7c | | internalurl | http://127.0.0.1:8774/v2/$(tenant_id)s | | publicurl | http://127.0.0.1:8774/v2/$(tenant_id)s | | region | RegionOne | | service_id | 5612ab143e9e4c7dbd174152577014d8 | +-------------+----------------------------------------+ +-------------+----------------------------------------+ | Property | Value | +-------------+----------------------------------------+ | adminurl | http://127.0.0.1:8776/v1/$(tenant_id)s | | id | fee4952baeac4394b285b49b7642b7b1 | | internalurl | http://127.0.0.1:8776/v1/$(tenant_id)s | | publicurl | http://127.0.0.1:8776/v1/$(tenant_id)s | | region | RegionOne | | service_id | 5ed1d0c1e7d047bc946218f9a9046b0a | +-------------+----------------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://127.0.0.1:9292/v2 | | id | f82bdd2537e841eda8c3dc10c83772d9 | | internalurl | http://127.0.0.1:9292/v2 | | publicurl | http://127.0.0.1:9292/v2 | | region | RegionOne | | service_id | 93fd957882be4538871b023278e8267b | +-------------+----------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://127.0.0.1:35357/v2.0 | | id | 60cf0abc7ba54bb9b5f09e6d0c505a08 | | internalurl | http://127.0.0.1:5000/v2.0 | | publicurl | http://127.0.0.1:5000/v2.0 | | region | RegionOne | | service_id | 66575a5c0dbc4763bdd207e85726f5b4 | +-------------+----------------------------------+ +-------------+--------------------------------------+ | Property | Value | +-------------+--------------------------------------+ | adminurl | http://127.0.0.1:8773/services/Admin | | id | 5a827e5daf004684884a89173fb7d87a | | internalurl | http://127.0.0.1:8773/services/Cloud | | publicurl | http://127.0.0.1:8773/services/Cloud | | region | RegionOne | | service_id | 410230c2679b4f57a7689b644559dbc9 | +-------------+--------------------------------------+ +-------------+----------------------------------+ | Property | Value | +-------------+----------------------------------+ | adminurl | http://127.0.0.1:9696/ | | id | 4e70d53ab72f491b81808247e6d890a4 | | internalurl | http://127.0.0.1:9696/ | | publicurl | http://127.0.0.1:9696/ | | region | RegionOne | | service_id | 13a1cd0634da46b281a4ef5460f9379f | +-------------+----------------------------------+ 获取admin的tenant-id: root@ubuntu:~# keystone tenant-list WARNING: Bypassing authentication using a token & endpoint (authentication credentials are being ignored). +----------------------------------+---------+---------+ | id | name | enabled | +----------------------------------+---------+---------+ | 6c2d7fd7a9474ecd8f5fac4729dfad08 | admin | True | | 189f9dd9c99240ebaae1c303b3ba85ab | service | True | +----------------------------------+---------+---------+
将此id替换novarc文件中相应的值,并重新source
11. 配置glance服务
替换glance-registry.conf 和glance-api.conf中的相关变量
sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/glance/glance-registry.conf sed -i "s/%SERVICE_USER%/service/g" /etc/glance/glance-registry.conf sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/glance/glance-registry.conf sed -i "s/#flavor=/flavor=keystone/g" /etc/glance/glance-registry.conf sed -i "s/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/root:[email protected]\/glance/g" /etc/glance/glance-registry.conf sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/glance/glance-api.conf sed -i "s/%SERVICE_USER%/service/g" /etc/glance/glance-api.conf sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/glance/glance-api.conf sed -i "s/#flavor=/flavor=keystone/g" /etc/glance/glance-api.conf sed -i "s/sqlite:\/\/\/\/var\/lib\/glance\/glance.sqlite/mysql:\/\/root:[email protected]\/glance/g" /etc/glance/glance-api.conf restart glance-api restart glance-registry
同步数据库
glance-manage db_sync
glance image-list
未输出东西则表示正常
12.配置libvirt
删除默认网桥
root@ubuntu:~# virsh net-destroy default Network default destroyed root@ubuntu:~# virsh net-undefine default Network default has been undefined
修改libvirt支持tcp监听
sed -i "s/#listen_tls = 0/listen_tls = 0/g" /etc/libvirt/libvirtd.conf sed -i "s/#listen_tcp = 1/listen_tcp = 1/g" /etc/libvirt/libvirtd.conf sed -i "s/#auth_tcp = "sasl"/auth_tcp = "none"/g" /etc/libvirt/libvirtd.conf sed -i "s/env libvirtd_opts=\"-d\"/env libvirtd_opts=\"-d -l\"/g" /etc/init/libvirt-bin.conf vi /etc/libvirt/qemu.conf cgroup_device_acl = [ "/dev/null", "/dev/full", "/dev/zero", "/dev/random", "/dev/urandom", "/dev/ptmx", "/dev/kvm", "/dev/kqemu", "/dev/rtc","/dev/hpet","/dev/net/tun" ] restart libvirt-bin
13. 配置nova
sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/nova/api-paste.ini sed -i "s/%SERVICE_USER%/service/g" /etc/nova/api-paste.ini sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/nova/api-paste.ini
vi 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 #instances_path=/smartstorage/nova/instances 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 allow_resize_to_same_host=true live_migration_flag=VIR_MIGRATE_UNDEFINE_SOURCE,VIR_MIGRATE_PEER2PEER,VIR_MIGRATE_LIVE #Scheduler my_ip=127.0.0.1 #default_schedule_zone=<None> node_availability_zone="zone_52" #reserved_host_memory_mb=512 #reserved_host_disk_mb=500 compute_scheduler_driver=nova.scheduler.simple.SimpleScheduler #scheduler_default_filters="AvailabilityZoneFilter,RamFilter,ComputeFilter" rabbit_host=127.0.0.1 nova_url=http://127.0.0.1:8774/v1.1/ sql_connection=mysql://root:[email protected]/nova # Auth use_deprecated_auth=false auth_strategy=keystone # Imaging service glance_api_servers=127.0.0.1:9292 image_service=nova.image.glance.GlanceImageService # Vnc configuration novnc_enabled=true novncproxy_base_url=http://10.51.166.10:6080/vnc_auto.html novncproxy_port=6080 vncserver_proxyclient_address=127.0.0.1 vncserver_listen=0.0.0.0 # Network settings network_api_class=nova.network.quantumv2.api.API quantum_url=http://127.0.0.1:9696 quantum_auth_strategy=keystone quantum_admin_tenant_name=service quantum_admin_username=service quantum_admin_password=password quantum_admin_auth_url=http://127.0.0.1:35357/v2.0 quantum_region_name=RegionOne libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver linuxnet_interface_driver=nova.network.linux_net.LinuxOVSInterfaceDriver #firewall_driver=nova.virt.libvirt.firewall.IptablesFirewallDriver firewall_driver=nova.virt.firewall.NoopFirewallDriver #security_group_api=nova.compute.api.SecurityGroupAPI #security_group_api=quantum quantum_use_dhcp=true fixed_range='' multi-host=true #Metadata service_quantum_metadata_proxy = True quantum_metadata_proxy_shared_secret = helloOpenStack metadata_host = 127.0.0.1 metadata_listen = 127.0.0.1 metadata_listen_port = 8775 # Cinder # volume_api_class=nova.volume.cinder.API osapi_volume_listen_port=5900 resume_guests_state_on_host_boot =True
vi /etc/nova/nova-compute.conf
[DEFAULT] libvirt_type=kvm compute_driver=libvirt.LibvirtDriver libvirt_ovs_bridge=br-int libvirt_vif_type=ethernet libvirt_vif_driver=nova.virt.libvirt.vif.LibvirtHybridOVSBridgeDriver libvirt_use_virtio_for_bridges=True
同步nova 数据库
nova-manage db sync
14. 配置cinder
启用iscsi
sed -i 's/false/true/g' /etc/default/iscsitarget sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/cinder/api-paste.ini sed -i "s/%SERVICE_USER%/service/g" /etc/cinder/api-paste.ini sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/cinder/api-paste.ini echo "sql_connection = mysql://root:[email protected]/cinder" >> /etc/cinder/cinder.conf echo "notification_driver=cinder.openstack.common.notifier.rpc_notifier" >> /etc/cinder/cinder.conf cinder-manage db sync
如果没有未使用的分区或者磁盘,只能使用虚拟文件来代替
dd if=/dev/zero of=cinder-volumes bs=1 count=0 seek=2G losetup /dev/loop2 cinder-volumes fdisk /dev/loop2 #Type in the followings: n p 1 ENTER ENTER t 8e w
创建cinder-volumes
pvcreate /dev/loop2
vgcreate cinder-volumes /dev/loop2
15.配置quantum
sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/quantum/metadata_agent.ini sed -i "s/%SERVICE_USER%/service/g" /etc/quantum/metadata_agent.ini sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/quantum/metadata_agent.ini sed -i "s/%SERVICE_TENANT_NAME%/service/g" /etc/quantum/quantum.conf sed -i "s/%SERVICE_USER%/service/g" /etc/quantum/quantum.conf sed -i "s/%SERVICE_PASSWORD%/password/g" /etc/quantum/quantum.conf
#打开LB支持
sed -i "s/# service_plugins =/service_plugins = quantum.plugins.services.agent_loadbalancer.plugin.LoadBalancerPlugin/g" /etc/quantum/quantum.conf
sed -i "s/sqlite:\/\/\/\/var\/lib\/quantum\/ovs.sqlite/mysql:\/\/root:[email protected]\/quantum/g" /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini vi /etc/quantum/plugins/openvswitch/ovs_quantum_plugin.ini
在尾部增加
[OVS] tenant_network_type = gre tunnel_id_ranges = 1:1000 enable_tunneling = True integration_bridge = br-int tunnel_bridge = br-tun local_ip = 10.51.166.16
配置open-vswitch
ovs-vsctl add-br br-int ovs-vsctl add-br br-ex ovs-vsctl add-port br-ex eth1
这部分可参考:
http://www.cnblogs.com/biangbiang/archive/2013/05/17/3083421.html
下面可以登录Dashboard使用了。
http://10.51.166.16/horizon