企业自建私有云-openstack-glance镜像服务(控制节点上)

  1. 数据库创库授权

    #创建glance数据库:
    CREATE DATABASE glance;
    #授予恰当的权限
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'GLANCE_CXK_DBPASS';
    GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'GLANCE_CXK_DBPASS';
    
  2. 在keystone创建glance用户,授权关联角色在任意一个节点

    source /sh/admin-openstack.sh
    
    #创建用户
    openstack user create --domain default --password GLANCE_CXK_PASS glance
    
    #关联
    #在service 项目(租户)上,给glance用户赋予admin角色
    openstack role add --project service --user glance admin
    
    #查看
    openstack role  assignment list
    
  3. 在keystone创建服务,注册api在任意一个节点

    openstack service create --name glance --description "OpenStack Image" image
    
    openstack endpoint create --region RegionOne image public http://vip:9292
    openstack endpoint create --region RegionOne  image internal http://vip:9292
    openstack endpoint create --region RegionOne image admin http://vip:9292
    
    #查看创建之后的api;
    openstack endpoint list
    
  4. 安装服务相关的软件包

    yum install -y openstack-glance openstack-utils python-openstackclient  python2-PyMySQL python-memcached  
    #glance-api服务运行在3个控制节点,使用ceph的话进行安装
    yum install python-rbd -y
    
  5. 修改配置文件

    #备份配置文件
    cp /etc/glance/glance-api.conf{,.bak}
    egrep -v '^$|^#' 		/etc/glance/glance-api.conf.bak >/etc/glance/glance-api.conf
    cp /etc/glance/glance-registry.conf{,.bak}
    egrep -v '^$|^#' 		/etc/glance/glance-registry.conf.bak >/etc/glance/glance-registry.conf
    
    vi /etc/glance/glance-api.conf
    [DEFAULT]
    bind_port = 9292
    log_file = /var/log/glance/api.log
    log_dir = /var/log/glance
    #启用映像的写时复制,大大降低了进程对资源的浪费
    show_image_direct_url = True
    debug=true
    [database]
    connection = mysql+pymysql://glance:GLANCE_CXK_DBPASS@192.168.188.29/glance
    transport_url = rabbit://openstack:RABBIT_CXK_PASS@openstack-controller01:5672,openstack:RABBIT_CXK_PASS@openstack-controller02:5672,openstack:RABBIT_CXK_PASS@openstack-controller03:5672
    
    [keystone_authtoken]
    www_authenticate_uri  = http://vip:5000
    auth_url = http://vip:5000
    cache = true
    token_cache_time = 3600
    memcached_servers = openstackcontroller1ip:11211,openstackcontroller2ip:11211,openstackcontroller3ip:11211
    auth_type = password
    project_domain_name = Default
    user_domain_name = Default
    project_name = service
    username = glance
    password = GLANCE_CXK_PASS
    
    [paste_deploy]
    flavor = keystone
    
    [glance_store]
    #nfs配置
    stores = file,http
    default_store = file
    filesystem_store_datadir = /data/glance
    #ceph配置
    stores = rbd
    default_store = rbd
    rbd_store_pool = images
    rbd_store_user = glance
    rbd_store_ceph_conf = /etc/ceph/ceph.conf
    #单位对象大小,默认8,8的n次方
    rbd_store_chunk_size = 8
    
    vi /etc/glance/glance-registry.conf
    [DEFAULT]
    bind_port = 9191
    log_file = /var/log/glance/registry.log
    log_dir = /var/log/glance
    debug = true
    
    [database]
    connection = mysql+pymysql://glance:GLANCE_CXK_DBPASS@192.168.188.29/glance
    
    [keystone_authtoken]
    www_authenticate_uri = http://vip:5000
    auth_url = http://vip:5000
    cache = true
    token_cache_time = 3600
    memcached_servers = openstackcontroller1ip:11211,openstackcontroller2ip:11211,openstackcontroller3ip:11211
    auth_type = password
    project_domain_name = Default
    user_domain_name = Default
    project_name = service
    username = glance
    password = GLANCE_CXK_PASS
    
    [paste_deploy]
    flavor = keystone
    
  6. 初始化数据在任意一个节点

    su -s /bin/sh -c "glance-manage db_sync" glance
    mysql -u glance -pGLANCE_CXK_DBPASS -e "use glance;show tables;"
    
  7. 启动服务

    systemctl start openstack-glance-api.service openstack-glance-registry.service
    systemctl status openstack-glance-api.service openstack-glance-registry.service
    systemctl enable openstack-glance-api.service  openstack-glance-registry.service
    
  8. 验证

    #在任意一个控制节点上上传镜像测试
    cirros-0.3.5-x86_64-disk.img 
    
    #镜像转换
    #从QEMU中检索块设备映像信息
    qemu-img info cirros-0.3.5-x86_64-disk.img 
    #将镜像从qcow2格式转换为raw格式
    qemu-img convert -f qcow2 -O raw 
    cirros-0.3.5-x86_64-disk.img 	cirros-0.3.5-x86_64-disk.raw
    source /sh/admin-openstack.sh
    
    #使用qcow2磁盘格式,bare容器格式,上传镜像到镜像服务并设置公共可见
    #openstack image create "cirros" 
    #	--file cirros-0.3.5-x86_64-disk.img 
    #	--disk-format qcow2 --container-format bare 
    #	--public
    
    对接 Ceph 之后,通常会以 RAW 格式创建 Glance Image,而不再使用 QCOW2 格			式,否则创建虚拟机时需要进行镜像复制,没有利用 Ceph RBD COW 的优秀			特性。
    openstack image create "cirros-ceph"
    	--file cirros-0.3.5-x86_64-disk.raw 
    	--disk-format raw --container-format bare 
    	--public 
    
    #检查是否上传成功
    openstack image list
    
    #删除镜像 
    glance image-delete 镜像id
    

喜欢的亲可以关注点赞评论哦!以后每天都会更新的哦!本文为小编原创文章; 文章中用到的文件、安装包等可以加小编联系方式获得;
欢迎来交流小编联系方式VX:CXKLittleBrother 进入运维交流群

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

含义小哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值