openstack搭建
1、虚拟机部署规划
主机 | 主机名 | IP规划 | |
---|---|---|---|
实例通讯 | 内部通讯 | ||
控制节点 | controller | 192.168.10.144 | 192.168.1.144 |
实例节点 | compute | 192.168.10.145 | 192.168.1.145 |
2、硬件配置
主机名 | 内存 | 逻辑CPU数量 | 硬盘容量 |
---|---|---|---|
controller | 4G | 4 | 80G |
compute | 4G | 4 | 80G+20G |
3、安装centos7,命名compute/controller
在此,我使用centos7系统,内存给了4G,磁盘空间给了80G和20G两个磁盘,处理器2个,网络为NAT模式
虚拟机设置:
打开虚拟化引擎,并给两个磁盘,是为了给openstack一个安装空间,不可省略
4、配置yum源
- 控制节点controller:
创建目录/opt/centos
配置本地yum源:
上传镜像
配置
##CentOS-7挂载
[root@controller ~]# mount -o loop ./CentOS-7-x86_64-DVD-1511centOS7.iso /mnt/
mount: /dev/loop0 写保护,将以只读方式挂载
##复制
[root@controller ~]# cp -rf /mnt/* /opt/centos
##卸载
[root@controller opt]# umount /mnt/
##XianDian挂载
[root@controller ~]# mount -o loop ./XianDian-IaaS-v2.2.iso /mnt/
mount: /dev/loop0 写保护,将以只读方式挂载
##复制
[root@controller opt]# cp -rf /mnt/* /opt/
[root@controller opt]# umount /mnt/
构建:
[root@controller yum.repos.d]# mkdir centos
[root@controller yum.repos.d]# mv CentOS-* centos/
[root@controller yum.repos.d]#vi local.repo
[root@controller yum.repos.d]# ls
centos local.repo
[root@controller yum.repos.d]# cat local.repo
[centos]
name=centos
baseurl=file:///opt/centos
gpgcheck=0
enabled=1[iaas]
name=iaas
baseurl=file:///opt/iaas-repo
gpgcheck=0
enabled=1
缓存:
##清除
[root@controller yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: centos iaas
Cleaning up everything
##新建
[root@controller yum.repos.d]# yum makecache
已加载插件:fastestmirror
centos | 3.6 kB 00:00
iaas | 2.9 kB 00:00
(1/7): centos/group_gz | 155 kB 00:00
(2/7): centos/filelists_db | 2.9 MB 00:00
(3/7): centos/primary_db | 2.8 MB 00:00
(4/7): centos/other_db | 1.2 MB 00:00
(5/7): iaas/primary_db | 2.3 MB 00:00
(6/7): iaas/filelists_db | 1.9 MB 00:00
(7/7): iaas/other_db | 692 kB 00:00
Determining fastest mirrors
元数据缓存已建立
[root@controller yum.repos.d]#
建立FTP服务:
安装软件包
[root@controller yum.repos.d]# yum install iaas-xiandian vsftpd -y
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 iaas-xiandian.x86_64.0.2.2-0 将被 安装
---> 软件包 vsftpd.x86_64.0.3.0.2-11.el7_2 将被 安装
--> 解决依赖关系完成
...
已安装:iaas-xiandian.x86_64 0:2.2-0 vsftpd.x86_64 0:3.0.2-11.el7_2 完毕!
[root@controller yum.repos.d]#
配置软件包
[root@controller yum.repos.d]# vi /etc/vsftpd/vsftpd.conf
[root@controller yum.repos.d]# tail -n 1 /etc/vsftpd/vsftpd.conf
anon_root=/opt/
设置开机自启
[root@controller yum.repos.d]# systemctl start vsftpd
[root@controller yum.repos.d]# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
- 计算节点compute:
删除本地源文件,创建本地源文件在文件中填入以下内容:
[root@compute yum.repos.d]# vi local.repo
[root@compute yum.repos.d]# cat local.repo
[centos]
name=centos
baseurl=ftp://192.168.10.144/centos
gpgcheck=0
enabled=1[iaas]
name=iaas
baseurl=ftp://192.168.10.144/iaas-repo
gpgcheck=0
enabled=1
##缓存
[root@compute yum.repos.d]# yum makecache
已加载插件:fastestmirror
centos | 3.6 kB 00:00:00
iaas | 2.9 kB 00:00:00
(1/7): centos/group_gz | 155 kB 00:00:01
(2/7): centos/filelists_db | 2.9 MB 00:00:01
(3/7): centos/other_db | 1.2 MB 00:00:00
(4/7): centos/primary_db | 2.8 MB 00:00:01
(5/7): iaas/filelists_db | 1.9 MB 00:00:01
(6/7): iaas/primary_db | 2.3 MB 00:00:01
(7/7): iaas/other_db | 692 kB 00:00:00
Determining fastest mirrors
元数据缓存已建立
5、主机名
##controller节点
[root@localhost ~]#
[root@localhost ~]# hostnamectl set-hostname controller
[root@localhost ~]# bash
[root@controller ~]# hostname
controller##compute节点
[root@bogon ~]# hostnamectl set-hostname compute
[root@bogon ~]# bash
[root@compute ~]# hostname
compute
6、配置静态IP
双节点配置
[root@bogon /]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 [root@compute ~]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736
TYPE="Ethernet"
BOOTPROTO="static"##静态
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eno16777736"
UUID="dada9ac5-ddca-4a1b-bfb2-05f3e8333495"
DEVICE="eno16777736"
ONBOOT="yes"
IPADDR=192.168.10.145##IP
GATEWAY=192.168.10.2##网关
NETMASK=255.255.255.0##子网掩码
DNS1=8.8.8.8##解析
DNS2=114.114.114.114##解析
[root@compute ~]#
#重启网卡
[root@compute /]# systemctl restart network
[root@compute ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:4d:d9:bf brd ff:ff:ff:ff:ff:ffinet 192.168.10.145/24 brd 192.168.10.255 scope global eno16777736valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe4d:d9bf/64 scope link valid_lft forever preferred_lft forever
3: eno33554960: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:4d:d9:c9 brd ff:ff:ff:ff:ff:ffinet 192.168.1.145/24 brd 192.168.1.255 scope global eno33554960valid_lft forever preferred_lft foreverinet6 fe80::20c:29ff:fe4d:d9c9/64 scope link valid_lft forever preferred_lft forever
#ping baidu
[root@compute ~]# ping www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18: icmp_seq=1 ttl=128 time=61.9 ms
64 bytes from 39.156.66.18: icmp_seq=2 ttl=128 time=67.1 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 61.994/64.562/67.130/2.568 ms
[root@compute ~]#
7、关闭防火墙,并禁用SLINUX
双机配置
[root@compute ~]# systemctl stop firewalld
[root@compute ~]# systemctl disable firewalld
[root@compute ~]# vi /etc/selinux/config
[root@compute ~]# cat /etc/selinux/config# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted [root@compute ~]# reboot
8、修改主机映射
配置解析双机
[root@c ~]# vi /etc/hosts
[root@compute ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.144 controller
192.168.10.145 compute
9、脚本文件配置
##控制节点
[root@controller ~]# cat /etc/xiandian/openrc.sh
#--------------------system Config--------------------##
#Controller Server Manager IP. example:x.x.x.x
HOST_IP=192.168.10.144#Controller Server hostname. example:controller
HOST_NAME=controller#Compute Node Manager IP. example:x.x.x.x
HOST_IP_NODE=192.168.10.145#Compute Node hostname. example:compute
HOST_NAME_NODE=compute#--------------------Rabbit Config ------------------##
#user for rabbit. example:openstack
RABBIT_USER=openstack#Password for rabbit user .example:000000
RABBIT_PASS=000000#--------------------MySQL Config---------------------##
#Password for MySQL root user . exmaple:000000
DB_PASS=000000#--------------------Keystone Config------------------##
#Password for Keystore admin user. exmaple:000000
DOMAIN_NAME=demo
ADMIN_PASS=000000
DEMO_PASS=000000#Password for Mysql keystore user. exmaple:000000
KEYSTONE_DBPASS=000000#--------------------Glance Config--------------------##
#Password for Mysql glance user. exmaple:000000
GLANCE_DBPASS=000000#Password for Keystore glance user. exmaple:000000
GLANCE_PASS=000000#--------------------Nova Config----------------------##
#Password for Mysql nova user. exmaple:000000
NOVA_DBPASS=000000#Password for Keystore nova user. exmaple:000000
NOVA_PASS=000000#--------------------Neturon Config-------------------##
#Password for Mysql neutron user. exmaple:000000
NEUTRON_DBPASS=000000#Password for Keystore neutron user. exmaple:000000
NEUTRON_PASS=000000#metadata secret for neutron. exmaple:000000
METADATA_SECRET=000000#External Network Interface. example:eth1
INTERFACE_NAME=eno33554960#First Vlan ID in VLAN RANGE for VLAN Network. exmaple:101
minvlan=#Last Vlan ID in VLAN RANGE for VLAN Network. example:200
maxvlan=#--------------------Cinder Config--------------------##
#Password for Mysql cinder user. exmaple:000000
CINDER_DBPASS=000000#Password for Keystore cinder user. exmaple:000000
CINDER_PASS=000000#Cinder Block Disk. example:md126p3
BLOCK_DISK=#--------------------Trove Config--------------------##
#Password for Mysql Trove User. exmaple:000000
TROVE_DBPASS=000000#Password for Keystore Trove User. exmaple:000000
TROVE_PASS=000000#--------------------Swift Config---------------------##
#Password for Keystore swift user. exmaple:000000
SWIFT_PASS=000000#The NODE Object Disk for Swift. example:md126p4.
OBJECT_DISK=#The NODE IP for Swift Storage Network. example:x.x.x.x.
STORAGE_LOCAL_NET_IP=#--------------------Heat Config----------------------##
#Password for Mysql heat user. exmaple:000000
HEAT_DBPASS=000000#Password for Keystore heat user. exmaple:000000
HEAT_PASS=000000#--------------------Ceilometer Config----------------##
#Password for Mysql ceilometer user. exmaple:000000
CEILOMETER_DBPASS=000000#Password for Keystore ceilometer user. exmaple:000000
CEILOMETER_PASS=000000#--------------------AODH Config----------------##
#Password for Mysql AODH user. exmaple:000000
AODH_DBPASS=000000#Password for Keystore AODH user. exmaple:000000
AODH_PASS=000000
[root@controller ~]#
[root@controller ~]# source iaas-pre-host.sh
##依次运行以下脚本:
iaas-install-mysql.sh
iaas-install-keystone.sh
iaas-install-glance.sh
iaas-install-nova-controller.sh
iaas-install-neutron-controller.sh
iaas-install-neutron-controller-gre.sh
iaas-install-dashboard.sh
##计算节点
[root@compute ~]# scp 192.168.10.144:/etc/xiandian/openrc.sh openrc.sh
The authenticity of host '192.168.10.144 (192.168.10.144)' can't be established.
ECDSA key fingerprint is ef:3c:3f:33:12:a8:b9:69:7a:17:af:e3:6e:10:92:8c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.144' (ECDSA) to the list of known hosts.
root@192.168.10.144's password:
openrc.sh 100% 3027 3.0KB/s 00:00
[root@compute ~]# ls
[root@compute ~]# source iaas-pre-host.sh
##依次运行以下脚本:
iaas-install-nova-compute.sh
iaas-install-neutron-compute.sh
iaas-install-neutron-compute-gre.sh
10、访问
ure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.10.144’ (ECDSA) to the list of known hosts.
root@192.168.10.144’s password:
openrc.sh 100% 3027 3.0KB/s 00:00
[root@compute ~]# ls
[root@compute ~]# source iaas-pre-host.sh
##依次运行以下脚本:
iaas-install-nova-compute.sh
iaas-install-neutron-compute.sh
iaas-install-neutron-compute-gre.sh
### 10、访问### 浏览器访问http://192.168.10.144/dashboard