Glance组件服务在云端主要作用是给计算节点安装实例时,提供实例镜像文件。另外采用了NFS文件管理系统作为镜像文件的后端存储系统,方便三个控制节点共用同一个共享。
1)在controller1上创建glance数据库
```
MariaDB [(none)]> CREATE DATABASE glance;
```
2)在controller1上创建数据库用户并赋予权限
```
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' IDENTIFIED BY 'yjscloud';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' IDENTIFIED BY 'yjscloud';
```
3)在controller1上创建glance用户及赋予admin权限
```
source /root/admin-openrc
openstack user create --domain default glance --password yjscloud
openstack role add --project service --user glance admin
```
4)在controller1上创建image服务
```
openstack service create --name glance --description "OpenStack Image service" image
```
5)在controller1上创建glance的endpoint
```
openstack endpoint create --region RegionOne image public http://yjscloud.com:9292
openstack endpoint create --region RegionOne image internal http://yjscloud.com:9292
openstack endpoint create --region RegionOne image admin http://yjscloud.com:9292
```
6)在controller1、2、3上安装glance相关rpm包
```
yum install openstack-glance -y
```
7)在controller1、2、3上修改glance配置文件`/etc/glance/glance-api.conf`
注意把配置文件的密码设置成你自己的
```
cp /etc/glance/glance-api.conf /etc/glance/glance-api.conf.bak
>/etc/glance/glance-api.conf
openstack-config --set /etc/glance/glance-api.conf DEFAULT debug False
openstack-config --set /etc/glance/glance-api.conf DEFAULT verbose True
openstack-config --set /etc/glance/glance-api.conf DEFAULT bind_host controller1
openstack-config --set /etc/glance/glance-api.conf DEFAULT bind_port 9393
openstack-config --set /etc/glance/glance-api.conf DEFAULT registry_host controller1
openstack-config --set /etc/glance/glance-api.conf DEFAULT registry_port 9191
openstack-config --set /etc/glance/glance-api.conf DEFAULT auth_region RegionOne
openstack-config --set /etc/glance/glance-api.conf DEFAULT registry_client_protocol http
openstack-config --set /etc/glance/glance-api.conf DEFAULT show_image_direct_url False
openstack-config --set /etc/glance/glance-api.conf DEFAULT workers 4
openstack-config --set /etc/glance/glance-api.conf DEFAULT backlog 4096
openstack-config --set /etc/glance/glance-api.conf DEFAULT image_cache_dir /var/lib/glance/image-cache
openstack-config --set /etc/glance/glance-api.conf DEFAULT rpc_backend rabbit
openstack-config --set /etc/glance/glance-api.conf DEFAULT scrub_time 43200
openstack-config --set /etc/glance/glance-api.conf DEFAULT delayed_delete False
openstack-config --set /etc/glance/glance-api.conf DEFAULT enable_v1_api False
openstack-config --set /etc/glance/glance-api.conf DEFAULT enable_v2_api True
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_hosts controller1:5672,controller2:5672,controller3:5672
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_userid openstack
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_password yjscloud
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_use_ssl False
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_ha_queues True
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_retry_interval 1
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_retry_backoff 2
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit rabbit_max_retries 0
openstack-config --set /etc/glance/glance-api.conf oslo_messaging_rabbit amqp_durable_queues False
openstack-config --set /etc/glance/glance-api.conf oslo_concurrency lock_path /var/lock/glance
openstack-config --set /etc/glance/glance-api.conf database connection mysql+pymysql://glance:yjscloud@yjscloud.com/glance
openstack-config --set /etc/glance/glance-api.conf database idle_timeout 3600
openstack-config --set /etc/glance/glance-api.conf database max_pool_size 30
openstack-config --set /etc/glance/glance-api.conf database max_retries -1
openstack-config --set /etc/glance/glance-api.conf database retry_interval 2
openstack-config --set /etc/glance/glance-api.conf database max_overflow 60
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_uri http://yjscloud.com:5000
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_url http://yjscloud.com:35357
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken memcached_servers controller1:11211,controller2:11211,controller3:11211
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_domain_name default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken user_domain_name default
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken password yjscloud
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-api.conf keystone_authtoken token_cache_time -1
openstack-config --set /etc/glance/glance-api.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-api.conf glance_store stores file,http
openstack-config --set /etc/glance/glance-api.conf glance_store default_store file
openstack-config --set /etc/glance/glance-api.conf glance_store filesystem_store_datadir /var/lib/glance/images/
```
```
scp -p /etc/glance/glance-api.conf controller2:/etc/glance/glance-api.conf
scp -p /etc/glance/glance-api.conf controller3:/etc/glance/glance-api.conf
#注意更改controller编号
```
8)在controller1、2、3上修改glance配置文件`/etc/glance/glance-registry.conf`:
```
cp /etc/glance/glance-registry.conf /etc/glance/glance-registry.conf.bak
>/etc/glance/glance-registry.conf
openstack-config --set /etc/glance/glance-registry.conf DEFAULT debug False
openstack-config --set /etc/glance/glance-registry.conf DEFAULT verbose True
openstack-config --set /etc/glance/glance-registry.conf DEFAULT bind_host controller1
openstack-config --set /etc/glance/glance-registry.conf DEFAULT bind_port9191
openstack-config --set /etc/glance/glance-registry.conf DEFAULT workers 4
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_hosts controller1:5672,controller2:5672,controller3:5672
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_userid openstack
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_password yjscloud
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_use_ssl False
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_ha_queues True
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_retry_interval 1
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_retry_backoff 2
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit rabbit_max_retries 0
openstack-config --set /etc/glance/glance-registry.conf oslo_messaging_rabbit amqp_durable_queues False
openstack-config --set /etc/glance/glance-registry.conf database connection mysql+pymysql://glance:yjscloud@yjscloud.com/glance
openstack-config --set /etc/glance/glance-registry.conf database idle_timeout 3600
openstack-config --set /etc/glance/glance-registry.conf database max_pool_size 30
openstack-config --set /etc/glance/glance-registry.conf database max_retries -1
openstack-config --set /etc/glance/glance-registry.conf database retry_interval 2
openstack-config --set /etc/glance/glance-registry.conf database max_overflow 60
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_uri http://yjscloud.com:5000
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_url http://yjscloud.com:35357
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken memcached_servers controller1:11211,controller2:11211,controller3:11211
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken auth_type password
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_domain_name default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken user_domain_name default
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken project_name service
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken username glance
openstack-config --set /etc/glance/glance-registry.conf keystone_authtoken password yjscloud
openstack-config --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
openstack-config --set /etc/glance/glance-registry.conf glance_store filesystem_store_datadir /var/lib/glance/images/
openstack-config --set /etc/glance/glance-registry.conf glance_store os_region_name RegionOne
```
```
scp -p /etc/glance/glance-registry.conf controller2:/etc/glance/glance-registry.conf
scp -p /etc/glance/glance-registry.conf controller3:/etc/glance/glance-registry.conf
```
注意更改controller编号
9)controller1上同步glance数据库
```
su -s /bin/sh -c "glance-manage db_sync" glance
```
10)在controller1、2、3上启动glance机设置开机启动
```
systemctl enable openstack-glance-api.service openstack-glance-registry.service
systemctl restart openstack-glance-api.service openstack-glance-registry.service
systemctl status openstack-glance-api.service openstack-glance-registry.service
```
11)在controller1、2、3上将glance版本号写入环境变量openrc文件
```
echo " " >> /root/admin-openrc && \
echo " " >> /root/demo-openrc && \
echo "export OS_IMAGE_API_VERSION=2" | tee -a /root/admin-openrc /root/demo-openrc
```
12)搭建glance后端存储
因为是HA环境,3个控制节点必须要有一个共享的后端存储,不然request发起请求的时候不确定会去调用哪个控制节点的glance服务,如果没有共享存储池存镜像,那么会遇到创建VM时候image找不到的问题。这里我们采用NFS的方式把glance的后端存储建立起来,当然在实际的生产环境中一搬会用ceph、GlusterFS的方式,这里我们以NFS为例子来讲诉后端存储的搭建。
首先准备好一台物理机或者虚拟机,要求空间要大,网络最好是在万兆
这里我们用10.1.1.155这一台虚拟机
首先在这台机器上安装glance组件:
```
yum -y install openstack-glance python-glance python-glanceclient
```
其次安装NFS服务:
```
yum -y install -y nfs-utils rpcbind
```
创建glance image的存储路径并赋予glance用户相应权限:
```
mkdir -p /var/lib/glance/images
chown -R glance:glance /var/lib/glance/images
```
配置NFS把/var/lib/glance目录共享出去
```
vim /etc/exports
```
添加的内容:
```
/var/lib/glance *(rw,sync,no_root_squash)
```
启动相关服务,并把nfs设置开机启动:
```
systemctl enable rpcbind
systemctl enable nfs-server.service
systemctl start rpcbind
systemctl status nfs-server
```
让NFS共享目录生效:
```
showmount -e
```
接着在3个controller节点上做如下操作:
```
mount -t nfs 10.1.1.155:/var/lib/glance/images /var/lib/glance/images
echo "/usr/bin/mount -t nfs 10.1.1.155:/var/lib/glance/ /var/lib/glance/" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
df -h
```
13)在controller1上下载测试镜像文件
```
wget http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
```
14)在controller1上传镜像到glance
```
source /root/admin-openrc
glance image-create --name "cirros-0.3.4-x86_64" --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --visibility public --progress
```
![8-1-24](http://pded8ke3e.bkt.clouddn.com/8-1-24.jpg)
如果你做好了一个CentOS7.1系统的镜像,也可以用这命令操作,例:
```
glance image-create --name "CentOS7.1-x86_64" --file CentOS_7.1.qcow2 --disk-format qcow2 --container-format bare --visibility public --progress
```
查看镜像列表:
```
glance image-list
openstack image-list
```
15)其他两个节点重复6、7、8、10、11步骤
- 献给我的朋友们
- 一、个人对学习的看法
- 二、运维技能图谱
- 三、运维常用技能
- 3.1 Vim(最好用的编辑器)
- 3.2 Nginx & Tengine(Web服务)
- 1. Nginx介绍和部署
- 2. Nginx配置解析
- 3. Nginx常用模块
- 4. Nginx 的session 一致性问题
- 3.3 Tomcat(Web中间件)
- 3.4 Keepalived(负载均衡高可用)
- 3.5 Memcache(分布式缓存)
- 3.6 Zookeeper(分布式协调系统)
- 3.7 KVM(开源虚拟化)
- 1. 虚拟化介绍
- 2. KVM基础
- 3. 设置VNC和时间同步
- 4. kvm虚拟机快照备份
- 5. kvm虚拟机在线扩展磁盘
- 6. kvm虚拟机静态迁移
- 7. kvm虚拟机动态迁移
- 8. kvm虚拟机存储池配置
- 9. cpu添加虚拟化功能
- 3.8 GitLab(版本控制)
- 3.8.1 GitLab安装与汉化
- 3.9 Jenkins(运维自动化)
- 3.10 WAF(Web防火墙)
- 3.10.1初探WAF
- 四、常用数据库
- 4.1 MySQL(关系型数据库)
- 1. MySQL源码安装
- 4.2 Mongodb(适用与大数据分析的数据库)
- 4.3 Redis(非关系数据库)
- 五、自动化运维工具
- 5.1 Cobbler(系统自动化部署)
- 5.2 Ansible(自动化部署)
- 5.3 Puppet(自动化部署)
- 5.4 SaltStack(自动化运维)
- 六、存储
- 6.1 GFS(文件型存储)
- 6.2 Ceph(后端存储)
- 七、运维监控工具
- 7.1 对监控的理解
- 7.2 Zabbix(运维监控)
- 7.2.1 Zabbix简介
- 7.2.2 Zabbix服务部署
- 1. Zabbix服务端部署
- 2. Zabbix客服端部署
- 3. 配置前端展示
- 4. zabbix告警配置
- 7.2.3 Zabbix监控服务
- 1. 监控网络设备
- 2. 自定义Nginx监控
- 7.3 云镜(安全监控)
- 7.4 ELK(日志收集展示)
- 八、运维云平台
- 8.1 OpenStack(开源云操作系统)
- 8.1.1 OpenStack简介
- 8.1.2 实验架构设计
- 8.1.3 集群环境准备
- 8.1.4 controller节点部署
- 1. 安装Mariadb Galera Cluster集群
- 2. 安装RabbitMQ Cluster集群
- 3. 安装Pacemaker
- 4. 安装HAProxy
- 5. 安装配置Keystone
- 6. 安装配置glance
- 1. 制作镜像模板
- 7. 安装配置nova
- 8. 安装配置neutron
- 1. 配置虚拟机网络
- 9. 安装Dashboard
- 10. 安装配置cinder
- 8.1.5 compute节点部署
- 1. 安装相关软件包
- 2. 安装Neutron
- 3. 配置cinder
- 4. 创建第一个虚拟机
- 8.1.6 OpenStack报错处理
- 1. cinder僵尸卷删除
- 8.1.7 快速孵化虚拟机方案
- 8.1.8 Kolla容器化部署OpenStack
- 1. 单点部署
- 2. 多节点部署
- 8.2 Tstack(腾讯云平台)
- 8.3 K8s(微服务容器化)
- 九、运维编程技能
- 9.1 Shell(运维必会语言)
- 9.2 Python(万能的胶水语言)
- 十、Devops运维
- 10.1 理念
- 10.2 Devops实战