IP | 主机名 | 节点 |
---|---|---|
192.168.100.10 | Controller | 控制节点 |
192.168.100.20 | Compute | 计算节点 |
使用VMware创建两台云主机(使用Centos7.9镜像),云主机类型为4cpu,8G内存,100G磁盘及20G临时磁盘;需要给云主机两个网络接口,网络接口1为外部网络,作为云主机通信和管理使用,网络接口2设置为内部网络,作为一个网卡设备。
[root@localhost ~]# hostnamectl set-hostname controller
[root@localhost ~]# bash
bash
[root@controller ~]#
[root@localhost ~]# hostnamectl set-hostname compute
[root@localhost ~]# bash
[root@compute ~]#
[root@controller ~]# cat /etc/hosts
...
192.168.100.10 controller
192.168.100.20 compute
[root@compute ~]# cat /etc/hosts
...
192.168.100.10 controller
192.168.100.20 compute
[root@controller ~]# systemctl stop firewalld && systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@controller ~]# vi /etc/sysconfig/selinux
...
SELINUX=disabled
[root@controller ~]# setenforce 0
挂载镜像
[root@controller ~]# mkdir /opt/{centos,iaas}
[root@controller ~]# ls /opt/
centos iaas
[root@controller ~]# mount -o loop chinaskills_cloud_iaas_v2.0.3.iso /mnt/
c^Hmount: /dev/loop0 写保护,将以只读方式挂载
[root@controller ~]# cp -r /mnt/* /opt/iaas/
[root@controller ~]# umount /mnt/
[root@controller ~]# mount -o loop CentOS-7-x86_64-DVD-2009.iso /mnt/
mount: /dev/loop0 写保护,将以只读方式挂载
[root@controller ~]# cp -r /mnt/* /opt/centos/
[root@controller ~]# umount /mnt/
配置Controller节点Yum安装源文件local.repo,指定本地文件目录路径
[root@controller ~]# mv /etc/yum.repos.d/* /media/
[root@controller ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1
[iaas]
name=iaas
baseurl=file:///opt/iaas/iaas-repo
gpgcheck=0
enabled=1
在Controller节点使用Yum安装vsftpd服务,并将/opt目录下的文件分享出去
[root@controller ~]# yum install -y vsftpd
[root@controller ~]# echo "anon_root=/opt" >> /etc/vsftpd/vsftpd.conf
[root@controller ~]# systemctl restart vsftpd
[root@controller ~]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
配置Compute节点Yum源文件local.repo,指向Controller节点的共享文件目录路径
[root@compute ~]# mv /etc/yum.repos.d/* /media/
[root@compute ~]# vi /etc/yum.repos.d/local.repo
[centos]
name=centos
baseurl=ftp://controller/centos
gpgcheck=0
enabled=1
[iaas]
name=iaas
baseurl=ftp://controller/iaas/iaas-repo
gpgcheck=0
enabled=1
[root@compute ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 10.1G 0 part /home
├─sda3 8:3 0 7.9G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 81G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom
[root@compute ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x389319d7 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):N
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+5G
分区 1 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):N
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
分区号 (2-4,默认 2):
起始 扇区 (10487808-41943039,默认为 10487808):
将使用默认值 10487808
Last 扇区, +扇区 or +size{K,M,G} (10487808-41943039,默认为 41943039):+5G
分区 2 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):N
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (20973568-41943039,默认为 20973568):
将使用默认值 20973568
Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+5G
分区 3 已设置为 Linux 类型,大小设为 5 GiB
命令(输入 m 获取帮助):N
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): P
已选择分区 4
起始 扇区 (31459328-41943039,默认为 31459328):
将使用默认值 31459328
Last 扇区, +扇区 or +size{K,M,G} (31459328-41943039,默认为 41943039):+4G
分区 4 已设置为 Linux 类型,大小设为 4 GiB
命令(输入 m 获取帮助):W
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@compute ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 10.1G 0 part /home
├─sda3 8:3 0 7.9G 0 part [SWAP]
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 81G 0 part /
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 5G 0 part
├─sdb2 8:18 0 5G 0 part
├─sdb3 8:19 0 5G 0 part
└─sdb4 8:20 0 4G 0 part
sr0 11:0 1 4.4G 0 rom
[root@compute ~]#
(6)配置无密钥SSH
配置controller节点可以无密钥访问compute节点,配置完成后尝试 ssh连接compute
[root@controller ~]# ssh-keygen
[root@controller ~]# ssh-copy-id compute
[root@controller ~]# ssh compute
[root@compute ~]# exit
配置compute节点可以无密钥访问controller节点,配置完成后尝试 ssh连接controller
[root@compute ~]# ssh-keygen
[root@compute ~]# ssh-copy-id controller
[root@compute ~]# ssh controller
[root@controller ~]# exit
完成基础环境配置部署后,就可以开始部署安装OpenStack云平台了。
在Controller节点和compute节点安装Openstack云平台的安装脚本软件包
[root@controller ~]# yum install -y openstack-iaas
[root@compute ~]# yum install -y openstack-iaas
在controller节点和compute节点配置环境变量文件/etc/openstack/openrc.sh 按“i”键进入openrc.sh编辑模式
[root@controller ~]# vi /etc/openstack/openrc.sh
先把文件预处理
:%s/^.//g # 删除每一行开头的#
:%s/PASS=/PASS=Abc@1234 # 修改密码(密码可以设置成其他)
:%g/^#/d # 删除注释内容
:%g/^$/d # 删除空行
HOST_IP=192.168.100.10
HOST_PASS=Abc@1234 # controller节点root用户密码
HOST_NAME=controller
HOST_IP_NODE=192.168.100.20
HOST_PASS_NODE=Abc@1234 # compute节点root用户密码
HOST_NAME_NODE=compute
network_segment_IP=192.168.100.0/24
RABBIT_USER=openstack
RABBIT_PASS=Abc@1234
DB_PASS=Abc@1234
DOMAIN_NAME=demo
ADMIN_PASS=Abc@1234
DEMO_PASS=Abc@1234
KEYSTONE_DBPASS=Abc@1234
GLANCE_DBPASS=Abc@1234
GLANCE_PASS=Abc@1234
PLACEMENT_DBPASS=Abc@1234
PLACEMENT_PASS=Abc@1234
NOVA_DBPASS=Abc@1234
NOVA_PASS=Abc@1234
NEUTRON_DBPASS=Abc@1234
NEUTRON_PASS=Abc@1234
METADATA_SECRET=Abc@1234
INTERFACE_NAME=ens34 # 云主机第二张网卡名称
Physical_NAME=provider
minvlan=2
maxvlan=1000
CINDER_DBPASS=Abc@1234
CINDER_PASS=Abc@1234
BLOCK_DISK=sdb1 # compute 节点第一个分区名称
SWIFT_PASS=Abc@1234
OBJECT_DISK=sdb2 # compute 节点第二个分区名称
STORAGE_LOCAL_NET_IP=192.168.100.20
TROVE_DBPASS=Abc@1234
TROVE_PASS=Abc@1234
HEAT_DBPASS=Abc@1234
HEAT_PASS=Abc@1234
CEILOMETER_DBPASS=Abc@1234
CEILOMETER_PASS=Abc@1234
AODH_DBPASS=Abc@1234
AODH_PASS=Abc@1234
ZUN_DBPASS=Abc@1234
ZUN_PASS=Abc@1234
KURYR_PASS=Abc@1234
OCTAVIA_DBPASS=Abc@1234
OCTAVIA_PASS=Abc@1234
MANILA_DBPASS=Abc@1234
MANILA_PASS=Abc@1234
SHARE_DISK=sdb3 # compute 节点第三个分区名称
CLOUDKITTY_DBPASS=Abc@1234
CLOUDKITTY_PASS=Abc@1234
BARBICAN_DBPASS=Abc@1234
BARBICAN_PASS=Abc@1234
[root@controller ~]# scp /etc/openstack/openrc.sh compute:/etc/openstack/openrc.sh
在Controller节点和Compute节点都执行脚本iaas-pre-host.sh部署Openstack云平台基础环境。
完成后使用reboot命令重启虚拟机生效配置
[root@controller ~]# iaas-pre-host.sh
[root@compute ~]# iaas-pre-host.sh
在Controller节点执行
[root@controller ~]# iaas-install-mysql.sh
在Controller节点执行
[root@controller ~]# iaas-install-keystone.sh
在Controller节点执行
[root@controller ~]# iaas-install-glance.sh
在controller节点执行脚本部署Nova组件的控制服务
[root@controller ~]# iaas-install-placement.sh
[root@controller ~]# iaas-install-nova-controller.sh
执行完上面的脚本后,在compute节点执行脚本部署Nova组件的计算服务,这样就将compute节点的CPU、内存及磁盘资源添加到Openstack云平台时代资源池中了
[root@compute ~]# iaas-install-nova-compute.sh
在controller节点执行脚本部署Neutron组件的控制服务
[root@controller ~]# iaas-install-neutron-controller.sh
在compute节点执行脚本部署Neutron组件的控制服务
[root@compute ~]# iaas-install-neutron-compute.sh
在Controller节点执行脚本部署Dashboard组件服务
[root@controller ~]# iaas-install-dashboard.sh
安装完成后,使用浏览器访问Openstack云平台,访问地址为:
http://192.168.100.10/dashboard
用户名为:admin
密码为:Abc@1234
在Controller节点执行脚本部署Cinder组件的控制服务。
[root@controller ~]# iaas-install-cinder-controller.sh
controller节点脚本执行完成后,在compute节点执行脚本部署Cinder组件的计算服务
[root@compute ~]# iaas-install-cinder-compute.sh
在controller节点执行脚本部署Swift组件的控制服务
[root@controller ~]# iaas-install-swift-controller.sh
controller节点执行完成后,在compute节点执行脚本部署swift组件的计算服务
[root@compute ~]# iaas-install-swift-compute.sh
在controller节点下载镜像并上传cirros镜像
[root@controller ~]# source /etc/keystone/admin-openrc.sh
[root@controller ~]# openstack image create --disk-format qcow2 --container-format bare --file cirros-0.3.4-x86_64-disk.img cirros
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| checksum | ee1eca47dc88f4879d8a229cc70a07c6 |
| container_format | bare |
| created_at | 2023-02-01T20:09:10Z |
| disk_format | qcow2 |
| file | /v2/images/d019b7a2-0826-420b-95d1-7d548129c0cc/file |
| id | d019b7a2-0826-420b-95d1-7d548129c0cc |
| min_disk | 0 |
| min_ram | 0 |
| name | cirros |
| owner | 6a021198465e4fa780e35a3ff4202ddf |
| properties | os_hash_algo='sha512', os_hash_value='1b03ca1bc3fafe448b90583c12f367949f8b0e665685979d95b004e48574b953316799e23240f4f739d1b5eb4c4ca24d38fdc6f4f9d8247a2bc64db25d6bbdb2', os_hidden='False' |
| protected | False |
| schema | /v2/schemas/image |
| size | 13287936 |
| status | active |
| tags | |
| updated_at | 2023-02-01T20:09:10Z |
| virtual_size | None |
| visibility | shared |
+------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
在controller节点使用Openstack相关命令创建一个net网络
[root@controller ~]# openstack network create net --mtu 1350
+---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| admin_state_up | UP |
| availability_zone_hints | |
| availability_zones | |
| created_at | 2023-02-01T20:10:56Z |
| description | |
| dns_domain | None |
| id | bce45beb-074a-4ff1-b110-ef7316ff57f4 |
| ipv4_address_scope | None |
| ipv6_address_scope | None |
| is_default | False |
| is_vlan_transparent | None |
| location | cloud='', project.domain_id=, project.domain_name='demo', project.id='6a021198465e4fa780e35a3ff4202ddf', project.name='admin', region_name='', zone= |
| mtu | 1350 |
| name | net |
| port_security_enabled | True |
| project_id | 6a021198465e4fa780e35a3ff4202ddf |
| provider:network_type | vxlan |
| provider:physical_network | None |
| provider:segmentation_id | 2 |
| qos_policy_id | None |
| revision_number | 1 |
| router:external | Internal |
| segments | None |
| shared | False |
| status | ACTIVE |
| subnets | |
| tags | |
| updated_at | 2023-02-01T20:10:56Z |
+---------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~]# openstack subnet create --network net --subnet-range 10.0.0.0/24 --gateway 10.0.0.1 subnet
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
| allocation_pools | 10.0.0.2-10.0.0.254 |
| cidr | 10.0.0.0/24 |
| created_at | 2023-02-01T20:12:23Z |
| description | |
| dns_nameservers | |
| enable_dhcp | True |
| gateway_ip | 10.0.0.1 |
| host_routes | |
| id | 6b984b00-7184-4006-a245-dc4a55675b97 |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| location | cloud='', project.domain_id=, project.domain_name='demo', project.id='6a021198465e4fa780e35a3ff4202ddf', project.name='admin', region_name='', zone= |
| name | subnet |
| network_id | bce45beb-074a-4ff1-b110-ef7316ff57f4 |
| prefix_length | None |
| project_id | 6a021198465e4fa780e35a3ff4202ddf |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2023-02-01T20:12:23Z |
+-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@controller ~]# openstack flavor create --ram 2048 --disk 10 --vcpus 5 flavor2
+----------------------------+--------------------------------------+
| Field | Value |
+----------------------------+--------------------------------------+
| OS-FLV-DISABLED:disabled | False |
| OS-FLV-EXT-DATA:ephemeral | 0 |
| disk | 10 |
| id | dd92c3ab-f2a0-42dd-9388-c268c52723c9 |
| name | flavor2 |
| os-flavor-access:is_public | True |
| properties | |
| ram | 2048 |
| rxtx_factor | 1.0 |
| swap | |
| vcpus | 5 |
+----------------------------+--------------------------------------+
[root@controller ~]# openstack server create --network net1 --flavor flavor1 --image cirros server3
+-------------------------------------+------------------------------------------------+
| Field | Value |
+-------------------------------------+------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-SRV-ATTR:host | None |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None |
| OS-EXT-SRV-ATTR:instance_name | |
| OS-EXT-STS:power_state | NOSTATE |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | None |
| OS-SRV-USG:terminated_at | None |
| accessIPv4 | |
| accessIPv6 | |
| addresses | |
| adminPass | 3MdHgXbP3u8P |
| config_drive | |
| created | 2023-02-01T20:22:07Z |
| flavor | flavor1 (3cd78d95-977a-4d2a-9add-6f438e580462) |
| hostId | |
| id | 9f05531c-e610-44dd-897b-59b18d91d3f9 |
| image | cirros (d019b7a2-0826-420b-95d1-7d548129c0cc) |
| key_name | None |
| name | server3 |
| progress | 0 |
| project_id | 6a021198465e4fa780e35a3ff4202ddf |
| properties | |
| security_groups | name='default' |
| status | BUILD |
| updated | 2023-02-01T20:22:07Z |
| user_id | c5a402e3169f442d989b60ada2e000b5 |
| volumes_attached | |
+-------------------------------------+------------------------------------------------+
[root@controller ~]# openstack server list
+--------------------------------------+---------+--------+----------------------+--------+---------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+---------+--------+----------------------+--------+---------+
| 9f05531c-e610-44dd-897b-59b18d91d3f9 | server3 | ACTIVE | net1=192.168.100.127 | cirros | flavor1 |
+--------------------------------------+---------+--------+----------------------+--------+---------+
登录Dashboard页面,在左侧菜单栏选择“项目→计算→实例”可以看到已经创建成功,仅测试云主机创建是否正常没有使用CRT连接云主机