云计算的概念
云计算是一种把 IT 资源当作服务来提供的手段。几乎所有 IT 资源都可以作为云服务来提供:应用程序、计算能力、存储容量、联网、编程工具,以至于通信服务和协作工具。云计算最早为 Google、Amazon 等其他扩建基础设施的大型互联网服务提供商所采用。于是产生一种架构:大规模扩展、水平分布的系统资源,抽象为虚拟 IT 服务,并作为持续配置、合用的资源进行管理。
Openstack和Cloudstack比较
CloudStack是一个轻量级的开源私有云部署产品,与openstack相比来说功能行更弱一些。它们两者的主要区别是平台架构不同:OpenStack采用分布式架构,灵活性好,不同的项目可以单独部署,因此可以很容易的根据实际需要进行功能组合,并且由于不同的项目间耦合性低,项目间功能划分明确,因此针对单独功能进行定制开发也非常方便,缺点是部署麻烦,每个项目都要部署配置一遍;CloudStack采用集中式的单体架构(Monolithic architecture),整个平台只有一个项目构成,不同模块之间通过的本地调用进行交互,在一台主机上就可以完成平台的部署,CloudStack因为只有一个项目,所以部署起来会相对容易很多,然而平台的扩展性就要相对弱一些。
在企业的应用中,Openstack可以用来搭建公有云,CloudStack一般会用来搭建供企业内部使用的私有云。
cloudstack 的架构图示:
CloudStack 安装部署
1、创建GlusterFS分布式文件系统
首先在要加入cluster中的两台host机器上部署GlusterFS的文件系统,使用GlusterFS文件系统来创建Primary Storage.
1
2
<code>yum </code><code>install</code> <code>–y centos-release-gluster37.noarch</code>
<code>yum --enablerepo=centos-gluster*-</code><code>test</code> <code>install</code> <code>glusterfs-server glusterfs-cli glusterfs-geo-replication</code>
将host主机的磁盘添加到存储池,并确认状态:
<code>gluster peer probe agent2</code>
<code>gluster peer status</code>
格式化新加入的磁盘为xfs格式,如果没有xfs的支持包需要安装:
3
4
5
6
7
8
9
10
11
<code>yum -y </code><code>install</code> <code>xfsprogs</code>
<code>fdisk</code> <code>/dev/sdb</code>
<code>n</code>
<code>p</code>
<code>1</code>
<code>enter</code>
<code>w</code>
<code># fdisk -l</code>
<code> </code><code>Device Boot Start End Blocks Id System</code>
<code>/dev/sdb1</code> <code>1 1305 10482381 83 Linux</code>
<code>mkfs.xfs -f </code><code>/dev/sdb1</code>
两台host分别挂载磁盘到指定的brick上(主存储目录):
<code>mount</code> <code>/dev/sdb1</code> <code>/export/primary</code>
创建复制卷:
<code># gluster volume create gv1 replica 2 agent1:/export/primary agent2:/export/primary force</code>
<code># gluster volume info</code>
<code># gluster volume start gv1</code>
修改配置文件为如下内容,主要是修改端口并添加一行配置,这样可以防止虚拟机数量限制:
# vim /etc/glusterfs/glusterd.vol
volume management
type mgmt/glusterd
option working-directory /var/lib/glusterd
option transport-type socket,rdma
option transport.socket.keepalive-time 10
option transport.socket.keepalive-interval 2
option transport.socket.read-fail-log off
option ping-timeout 0
option event-threads 1
option rpc-auth-allow-insecure on
option base-port 51152
end-volume
执行命令:
<code>gluster volume </code><code>set</code> <code>gv1 server.allow-insecure on</code>
手动测试能否挂载:
<code># mount -t glusterfs 127.0.0.1:/gv1 /mnt</code>
<code># df -h</code>
<code># umount /mnt</code>
2、CloudStack的管理主机安装master 软件
从官网下载这三个rpm包:
cloudstack-common
cloudstack-agent
cloudstack-management
安装master:
<code>yum </code><code>install</code> <code>-y cloudstack-common-4.8.0-1.el6.x86_64.rpm cloudstack-management-4.8.0-1.el6.x86_64.rpm</code>
安装NTP,设置nfs:
<code>yum -y </code><code>install</code> <code>ntp</code>
<code>chkconfig ntpd on</code>
<code>service ntpd start</code>
<code>yum -y </code><code>install</code> <code>nfs-utils</code>
<code>echo</code> <code>"/export/secondary *(rw,async,no_root_squash,no_subtree_check)"</code> <code>> </code><code>/etc/exports</code>
<code>mkdir</code> <code>/export/secondary</code>
<code>echo</code> <code>"/dev/sdb /export/secondary ext4 defaults 0 0"</code> <code>>> </code><code>/etc/fstab</code>
加入防火墙规则:
-A INPUT -m state --state NEW -p udp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 111 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 2049 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 32803 -j ACCEPT
-A INPUT -m state --state NEW -p udp --dport 32769 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -p udp --dport 892 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -p udp --dport 875 -j ACCEPT
-A INPUT -m state --state NEW -p tcp --dport 662 -j ACCEPT
-A INPUT -m state --state NEW -p udp --dport 662 -j ACCEPT
安装mysql,并在/etc/my.cnf 的mysqld模块添加如下参数:
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600
max_connections=350
log-bin=mysql-bin
binlog-format = 'ROW'
初始化数据库,修改配置:(当cloudstack配置出现问题时,可以通过删除库,重置数据库后再进行以下操作)
mysqladmin -uroot password 123456
mysql -uroot -p123456 -e "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456'";
cloudstack-setup-databases cloud:123456@localhost --deploy-as=root:123456
初始化cloudstack:
cloudstack-setup-management
下载KVM模板,并导入:
wget http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2
/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /export/secondary/ -f ./systemvm64template-4.6.0-kvm.qcow2.bz2 -h kvm -F
3、在两台host主机上安装cloudstack的agent端
<code> </code><code>yum </code><code>install</code> <code>-y cloudstack-common-4.8.0-1.el6.x86_64.rpm cloudstack-agent-4.8.0-1.el6.x86_64.rpm</code>
4、在agent1和agent2上安装open vSwich
open vSwich是一个虚拟交换系统,当我们创建上百或上千台虚拟机时,由于网络方面通信需求和管理需求就变得非常重要,而open vSwich可以对我们所创建的虚拟机进行网络方面的管理,如流量限制,访问权限等。
下载open vSwich软件包,并安装:
<code> </code><code>yum </code><code>install</code> <code>-y kmod-openvswitch-2.3.2-1.el6.x86_64.rpm openvswitch-2.3.2-1.x86_64.rpm</code>
修改配置文件,添加两行配置用于cloudstack识别KVM的open vSwitch:
<code>#vim /etc/cloudstack/agent/agent.properties </code>
<code>network.bridge.</code><code>type</code><code>=openvswitch</code>
<code>libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.OvsVifDriver</code>
启动open vSwich,验证open vSwich是否正确安装:
<code># lsmod|grep openvswitch</code>
<code>openvswitch 61824 0 </code>
<code>vxlan 24870 1 openvswitch</code>
<code>libcrc32c 1246 1 openvswitch</code>
5.设置agent端的网络
如果之前有配置过cloudstack,会在默认的eth0网卡上多出一个cloudbr0的桥接配置,需要将它删除,同时删除ifcfg-cloudbr0 文件。
在生产环境中,一般会让存储网络,管理网络和来宾网络三网分离,分别分配不同的网段,如果只有两块网卡,或者网络结构的限制,可以将存储网络和管理网络放在一个网段,来宾网络划分到另一个网络。实现这些就需要用到cloudstack高级网络功能。
在两台agent上使用Open vSwitch 实现手动桥接,将eth2作为trunk,桥接cloudbr2:
# vim ifcfg-cloudbr2
DEVICE=cloudbr2
IPV6INIT=no
ONBOOT=yes
TYPE=OVSBridge
BOOTPROTO=none
USERCTL=no
NM_CONTROLLED=no
STP=no
DEVICETYPE=ovs
----------------------------------------------
# vim ifcfg-eth2
DEVICE=eth2
TYPE=OVSPort
OVS_BRIDGE=cloudbr2
重启网络,查看设置是否生效:
<code># /etc/init.d/network restart</code>
<code># ovs-vsctl show</code>
<code>59d8677c-b958-493f-ac1c-f513dacfb07d</code>
<code> </code><code>Bridge </code><code>"cloudbr2"</code>
<code> </code><code>Port </code><code>"eth2"</code>
<code> </code><code>Interface </code><code>"eth2"</code>
<code> </code><code>Port </code><code>"cloudbr2"</code>
<code> </code><code>Interface </code><code>"cloudbr2"</code>
<code> </code><code>type</code><code>: internal</code>
<code> </code><code>ovs_version: </code><code>"2.3.2"</code>
登录CloudStack web界面,管理Cloudstack
在 “全局配置”中设置默认网关:
<a href="http://s2.51cto.com/wyfs02/M01/89/17/wKioL1gHZy6xiwz_AAFICWhgM2I577.jpg" target="_blank"></a>
重启master 上的cloudstack:
<code># /etc/init.d/cloudstack-management restart</code>
2、创建资源域
<a href="http://s5.51cto.com/wyfs02/M00/89/17/wKioL1gHaBugzsABAAFR4HYmp_A240.jpg" target="_blank"></a>
配置zone:
<a href="http://s5.51cto.com/wyfs02/M02/89/1A/wKiom1gHaP3ArqpRAAGFsMCfTKw355.jpg" target="_blank"></a>
这里只用了两个网络做为流量分离示例,在实际的生产环境中,如果要求比较高,可以给存储单独加一块网卡,将它拖动到对应的网卡,设置好对应的物理网卡和cloudstack的桥接网卡:
<a href="http://s4.51cto.com/wyfs02/M02/89/17/wKioL1gHayTguW7nAAItHsWcXQ0032.jpg" target="_blank"></a>
设置pod:
<a href="http://s5.51cto.com/wyfs02/M02/89/17/wKioL1gHbDngnm-YAAGN6HyFaS8212.jpg" target="_blank"></a>
设置来宾流量(生产场景以实际的网关IP为准,对应上分配的网段即可):
<a href="http://s5.51cto.com/wyfs02/M00/89/1A/wKiom1gHbfPggxusAAFEf4c_v30639.jpg" target="_blank"></a>
添加主机,主机使用管理网络:
<a href="http://s1.51cto.com/wyfs02/M00/89/17/wKioL1gHbxfT7qv_AAGBSyjU8No059.jpg" target="_blank"></a>
添加主存储:
<a href="http://s3.51cto.com/wyfs02/M02/89/17/wKioL1gHcYXQERn9AAGVRza_v5Y117.jpg" target="_blank"></a>
添加二级存储,使用管理网段:
<a href="http://s5.51cto.com/wyfs02/M00/89/1A/wKiom1gHci6REevGAAGJ54X1ZBY623.jpg" target="_blank"></a>
设置完之后启动资源域,一般第一次添加都会失败,需要重新添加主机,此时我们最好选择添加另外一台主机,看是否报错,然后添加主存储:
<a href="http://s3.51cto.com/wyfs02/M01/89/18/wKioL1gHfVyTgpGbAAEM_219nfU194.jpg" target="_blank"></a>
先添加完一台主机和存储,然后启动资源域,看能否正常运行,方便排错。
当启动成功后,我们可以通过open vSwitch的命令来查看网络状态:
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<code>f532d233-bb5d-4b56-be61-66442c5bca68</code>
<code> </code><code>Bridge </code><code>"cloud0"</code>
<code> </code><code>Port </code><code>"cloud0"</code>
<code> </code><code>Interface </code><code>"cloud0"</code>
<code> </code><code>Port </code><code>"vnet0"</code>
<code> </code><code>Interface </code><code>"vnet0"</code>
<code> </code><code>Port </code><code>"vnet3"</code>
<code> </code><code>Interface </code><code>"vnet3"</code>
<code> </code><code>Bridge </code><code>"cloudbr0"</code>
<code> </code><code>Port </code><code>"vnet1"</code>
<code> </code><code>Interface </code><code>"vnet1"</code>
<code> </code><code>Port </code><code>"eth0"</code>
<code> </code><code>Interface </code><code>"eth0"</code>
<code> </code><code>Port </code><code>"cloudbr0"</code>
<code> </code><code>Interface </code><code>"cloudbr0"</code>
<code> </code><code>Port </code><code>"vnet4"</code>
<code> </code><code>Interface </code><code>"vnet4"</code>
<code> </code><code>Port </code><code>"vnet2"</code>
<code> </code><code>tag: 1</code>
<code> </code><code>Interface </code><code>"vnet2"</code>
<code> </code><code>Port </code><code>"vnet5"</code>
<code> </code><code>Interface </code><code>"vnet5"</code>
3、open vSwitch的常见操作
以下操作都需要root权限运行,在所有命令中br0表示网桥名称,eth0为网卡名称。
添加网桥:
#ovs-vsctl add-br br0
列出open vswitch中的所有网桥:
#ovs-vsctl list-br
判断网桥是否存在
#ovs-vsctl br-exists br0
将物理网卡挂接到网桥:
#ovs-vsctl add-port br0 eth0
列出网桥中的所有端口:
#ovs-vsctl list-ports br0
列出所有挂接到网卡的网桥:
#ovs-vsctl port-to-br eth0
查看open vswitch的网络状态:
ovs-vsctl show
删除网桥上已经挂接的网口:
#vs-vsctl del-port br0 eth0
删除网桥:
#ovs-vsctl del-br br0
一些常见的排错思路
CloudStack在搭建的过程中经常会出现一些错误,特别是资源不够的情况,下面针对常见的故障提供一些解决问题的思路:
1、添加主机失败
确认主机内存是否够用,配置是否过低
主机客户端软件是否正常安装,重启libvirt
查看日志,看能否建立连接。
2、系统VM不能正常启动
查看日志,如果是使用的NFS挂载,测试挂载是否正常
master和agent的资源是否足够
3、添加镜像的时候显示“connection refused”
CloudStack 全局变量没有设置allow的网关和端口
4、web界面打开显示404
查看mysql是否启动,连接是否正常
检查cloudstack 服务状态
本文转自 酥心糖 51CTO博客,原文链接:http://blog.51cto.com/tryingstuff/1863661