天天看點

Cloudstack部署企業私有雲

雲計算的概念

雲計算是一種把 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>&gt; </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>&gt;&gt; </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