首先创建三台虚拟机, 一台作为openstack管理主机, 另外两天坐nova计算节点
openstack管理主机
2cpu, 7.5G内存, 50G硬盘
静态IP: 192.168.1.10
nova01,nova02计算节点
2cpu, 3.5G内存, 100G硬盘
[root@room9pc01 ~]# vim cv.sh //编写节本, 创建三台虚拟机
#!/bin/bash
while(($#));do
cd /var/lib/libvirt/images/
qemu-img create -f qcow2 -b .node_base.qcow2 "$1".img
sed "s,node_base,"$1"", .node_base.xml > /etc/libvirt/qemu/"$1".xml
virsh define /etc/libvirt/qemu/"$1".xml
virsh start $1
shift
done
:wq
[root@room9pc01 ~]# ./cv.sh os nova1 nova2
[root@room9pc01 ~]# virsh edit os
...
<memory unit='KiB'>8100000</memory> //修改内存大小
<currentMemory unit='KiB'>8100000</currentMemory>
<vcpu placement='static'>2</vcpu> //修改cpu个数
...
:wq
[root@room9pc01 ~]# virsh edit nova1
...
<memory unit='KiB'>4100000</memory> //修改内存大小
<currentMemory unit='KiB'>4100000</currentMemory>
<vcpu placement='static'>2</vcpu> //修改cpu个数
...
:wq
[root@room9pc01 ~]# virsh edit nova2
...
<memory unit='KiB'>4100000</memory> //修改内存大小
<currentMemory unit='KiB'>4100000</currentMemory>
<vcpu placement='static'>2</vcpu> //修改cpu个数
...
:wq
[root@room9pc01 ~]# virsh domblklist os
目标 源
------------------------------------------------
vda /var/lib/libvirt/images/os.img
[root@room9pc01 ~]# virsh blockresize --path /var/lib/libvirt/images/os.img --size 50G os
重新定义 '/var/lib/libvirt/images/os.img' 块设备大小
[root@room9pc01 ~]# virsh domblklist nova1
目标 源
------------------------------------------------
vda /var/lib/libvirt/images/nova1.img
[root@room9pc01 ~]# virsh blockresize --path /var/lib/libvirt/images/nova1.img --size 100G nova1
重新定义 '/var/lib/libvirt/images/nova1.img' 块设备大小
[root@room9pc01 ~]# virsh domblklist nova2
目标 源
------------------------------------------------
vda /var/lib/libvirt/images/nova2.img
[root@room9pc01 ~]# virsh blockresize --path /var/lib/libvirt/images/nova2.img --size 100G nova2
重新定义 '/var/lib/libvirt/images/nova2.img' 块设备大小
[root@room9pc01 ~]# virsh console os
[root@localhost ~]# hostnamectl set-hostname os
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.10
NEMASK=255.255.255.0
GATEWAY=192.168.1.254
:wq
[root@localhost ~]# reboot
ctrl+] //退出console模式
[root@room9pc01 ~]# virsh console nova1
[root@localhost ~]# hostnamectl set-hostname nova1
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.11
NEMASK=255.255.255.0
GATEWAY=192.168.1.254
:wq
[root@localhost ~]# reboot
[root@room9pc01 ~]# virsh console nova2
[root@localhost ~]# hostnamectl set-hostname nova2
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
# Generated by dracut initrd
DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE="Ethernet"
BOOTPROTO="static"
PERSISTENT_DHCLIENT="yes"
IPADDR=192.168.1.12
NEMASK=255.255.255.0
GATEWAY=192.168.1.254
:wq
[root@localhost ~]# reboot
[root@room9pc01 ~]# ssh [email protected]
[root@os ~]# LANG=C //语言必须设置为英文
[root@os ~]# lsblk //查看硬盘设备是否有多余空间
[root@os ~]# growpart /dev/vda 1 //扩容第一个分区
[root@os ~]# xfs_growfs /dev/vda1 //扩容文件系统
[root@os ~]# df -h //检查扩容结果
[root@room9pc01 ~]# ssh [email protected]
[root@nova1 ~]# LANG=C
[root@nova1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 100G 0 disk
-vda1 253:1 0 2G 0 part /
[root@nova1 ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=4192256 end=4194304 new: size=209713119,end=209715167
[root@nova1 ~]# xfs_growfs /dev/vda1
meta-data=/dev/vda1 isize=512 agcount=4, agsize=131008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=524032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 524032 to 26214139
[root@nova1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 100G 917M 100G 1% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.4M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 386M 0 386M 0% /run/user/0
[root@room9pc01 ~]# ssh [email protected]
[root@nova2 ~]# LANG=C
[root@nova2 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 100G 0 disk
-vda1 253:1 0 2G 0 part /
[root@nova2 ~]# growpart /dev/vda 1
CHANGED: partition=1 start=2048 old: size=4192256 end=4194304 new: size=209713119,end=209715167
[root@nova2 ~]# xfs_growfs /dev/vda1
meta-data=/dev/vda1 isize=512 agcount=4, agsize=131008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=524032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 524032 to 26214139
[root@nova2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 100G 917M 100G 1% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.4M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 386M 0 386M 0% /run/user/0
[root@room9pc01 ~]# ssh [email protected]
[root@os ~]# vim /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 192.168.1.254
:wq
[root@room9pc01 ~]# ssh [email protected]
[root@nova1 ~]# vim /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 192.168.1.254
:wq
[root@room9pc01 ~]# ssh [email protected]
[root@nova2 ~]# vim /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
nameserver 192.168.1.254
:wq
[root@os ~]# vim /etc/hosts
192.168.1.10 os
192.168.1.11 nova1
192.168.1.12 nova2
:wq
[root@os ~]# rsync -av /etc/hosts nova1:/etc/
[root@os ~]# rsync -av /etc/hosts nova2:/etc/
[root@os ~]# vim /etc/chrony.conf
...
server 192.168.1.254 iburst
...
:wq
[root@os ~]# systemctl restart chronyd
[root@os ~]# chronyc sources -v
210 Number of sources = 1
.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* gateway 3 6 17 4 +2824ns[-2725ns] +/- 14ms
[root@nova1 ~]# vim /etc/chrony.conf
[root@nova1 ~]# systemctl restart chronyd
[root@nova2 ~]# vim /etc/chrony.conf
[root@nova2 ~]# systemctl restart chronyd
[root@room9pc01 ~]# cd /var/ftp/
[root@room9pc01 ftp]# mkdir -p openstack extras
[root@room9pc01 openstack]# mount RHEL7-extras.iso /var/ftp/extras/
[root@room9pc01 openstack]# mount RHEL7OSP-10.iso /var/ftp/openstack/
[root@os ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/centos-1804"
enabled=1
gpgcheck=0
[openstack1]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-rpms"
enabled=1
gpgcheck=0
[openstack2]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/openstack/rhel-7-server-openstack-10-devtools-rpms"
enabled=1
gpgcheck=0
[extras]
name=CentOS-$releasever - Base
baseurl="ftp://192.168.1.254/extras"
enabled=1
gpgcheck=0
:wq
[root@os ~]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
extras | 2.9 kB 00:00
local_repo | 3.6 kB 00:00
openstack1 | 2.9 kB 00:00
openstack2 | 2.9 kB 00:00
(1/5): extras/primary_db | 43 kB 00:00
(2/5): openstack1/primary_db | 318 kB 00:00
(3/5): openstack2/primary_db | 3.7 kB 00:00
(4/5): local_repo/group_gz | 166 kB 00:00
(5/5): local_repo/primary_db | 5.9 MB 00:00
源标识 源名称 状态
extras CentOS-7 - Base 76
local_repo CentOS-7 - Base 9,911
openstack1 CentOS-7 - Base 680
openstack2 CentOS-7 - Base 3
repolist: 10,670
[root@os ~]# rsync -av /etc/yum.repos.d/local.repo nova1:/etc/yum.repos.d/local.repo
[root@os ~]# rsync -av /etc/yum.repos.d/local.repo nova2:/etc/yum.repos.d/local.repo
[root@room9pc01 ~]# for i in 0 1 2
> do
> ssh [email protected]"$i" "yum -y install qemu-kvm libvirt-daemon libvirt-daemon-driver-qemu libvirt-client python-setuptools"
> ssh [email protected]"$i" "systemctl start libvirtd"
> ssh [email protected]"$i" "systemctl enable libvirtd"
> done
检查安装环境
安装部署openstack
[root@os ~]# yum -y install openstack-packstack
[root@os ~]# packstack --gen-answer-file=answer.ini //创建通用应答文件
Packstack changed given value to required value /root/.ssh/id_rsa.pub
[root@os ~]# vim answer.ini
修改answer.ini应答文件
一键部署openstack
[root@os ~]# packstack --answer-file=answer.ini
Horizon BUG处理
[root@os ~]# vim /etc/httpd/conf.d/15-horizon_vhost.conf
...
## Server aliases
ServerAlias 192.168.1.10
ServerAlias os
ServerAlias localhost
WSGIDaemonProcess apache group=apache processes=3 threads=10 user=apache
WSGIProcessGroup apache
WSGIApplicationGroup %{GLOBAL} //添加一行
WSGIScriptAlias /dashboard "/usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi"
:wq
[root@os ~]# systemctl reload httpd
管理项目
创建项目
创建用户
创建云主机类型
上传镜像
创建外网
使用普通用户test,创建外网子网wan
外网不需要开dhcp
创建内网
新建路由
增加路由接口
创建浮动 IP
创建安全组及规则
其他协议代表所有协议
创建云主机
绑定浮动IP
验证
增加计算节点
[root@os ~]# vim answer.ini //修改配置文件, 增加节点ip
[root@os ~]# packstack --answer-file=answer.ini //重新部署openstack, 步骤与第一个计算节点相同, 需要重新解决horizon的bug