部署Cloudstack環境(cloudstack manager+kvm,適合RHEL/CentOS)

系統:CentOS 6.3 x86_64html

版本:Cloudstack 4.2.1node



    CloudStack是一個開源的具備高可用性及擴展性的雲計算平臺。支持管理大部分主流的hypervisors,如KVM,XenServer,VMware,Oracle VM,Xen等。mysql

    同時CloudStack是一個開源雲計算解決方案。能夠加速高伸縮性的公共和私有云(IaaS)的部署、管理、配置。使用CloudStack做爲基礎,數據中心操做者能夠快速方便的經過現存基礎架構建立雲服務。linux

    CloudStack能夠經過組織和協調用戶的虛擬化資源,構建一個和諧的環境。CloudStack具備許多強大的功能,可讓用戶構建一個安全的多租戶雲計算環境。web

    CloudStack的前身是Cloud.com,後被思傑收購。英特爾、阿爾卡特-朗迅、瞻博網絡、博科等都已宣佈支持CloudStack。2011年7月,Citrix收購Cloud.com,並將CloudStack 100%開源。2012年4月5日,Citrix又宣佈將其擁有的CloudStack開源軟件交給Apache軟件基金會管理。CloudStack已經有了許多商用客戶,包括GoDaddy、英國電信、日本電報電話公司、塔塔集團、韓國電信等。sql

    

    當前最新版本爲4.2.1數據庫

    官網:http://cloudstack.apache.org/ apache

    下載地址:http://cloudstack.apt-get.eu/rhel/4.2/ vim

    中國用戶組:http://www.cloudstack-china.org/ 安全

    思傑:http://www.citrix.com.cn/products/CloudStack/index.aspx


環境狀況:

Cloudstack Manager、Mysql:10.1.6.30

KVM Hypervisor、Cloudstack Agent:10.1.6.20

NFS:

主存儲:10.1.6.20:/export/primary

二級存儲:10.1.6.20:/export/secondary

網絡(使用簡單網絡,公有網絡和私有網絡都是一個網段):

cloudstack管理網絡:10.1.6.200-10.1.6.205

來賓網絡:10.1.6.206-10.1.6.215

存儲網絡:10.1.6.216-10.1.6.220


1、Apache Cloudstack Manager部署

經過UI或API的方式,使用Management服務進行雲資源管理。

一、Yum源配置

# vim /etc/yum.repos.d/cloudstack.repo
[cloudstack]
name=cloudstack
baseurl=http://cloudstack.apt-get.eu/rhel/4.2/
enabled=1
gpgcheck=0


因網絡慢問題,能夠先下載全部安裝包,而後建立本地源:

yum -y install httpd createrepo
wget -c -r -nd -A rpm http://cloudstack.apt-get.eu/rhel/4.2/ -P /var/www/html/4.2
createrepo /var/www/html/4.2/
service httpd start


-c 斷點續傳

-nd 遞歸下載時不建立一層一層的目錄,把全部的文件下載到當前目錄

-A 指定分號分隔的被接受擴展名的列表


yum配置改成:

[cloudstack]
name=cloudstack
baseurl=http://<http_server_ip>/4.2  #修改爲本身服務器的IP地址
enabled=1
gpgcheck=0


二、安裝管理服務

2.1 操做系統準備

a、檢查主機名是否符合FQDN格式:

hostname --fqdn

cloudstack.yaukb.com


如不是,修改配置文件

# vim /etc/sysconfig/network
HOSTNAME=yau620.yaukb.com


# hostname cloudstack.yaukb.com


# vim /etc/hosts
10.1.6.30   cloudstack.yaukb.com


b、配置NTP

yum -y install ntp
service ntpd start
chkconfig ntpd on


2.2 安裝管理服務

yum -y install cloudstack-management


當使用xenserver作Hypervisor時,需下載vhd-util工具:

wget http://download.cloud.com.s3.amazonaws.com/tools/vhd-util
cp vhd-util /usr/share/cloudstackcommon/scripts/vm/hypervisor/xenserver


2、安裝mysql

一、Mysql跟Management服務安裝在一塊兒,使用yum安裝:

yum -y install mysql-server


二、修改配置文件(在[mysqld]下面添加):

# vim /etc/my.cnf
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600
max_connections=350
log-bin=mysql-bin
binlog-format = 'ROW'


三、啓動服務:

service mysqld start
chkconfig mysqld on


四、查看服務是否啓動:

netstat -ntlp|grep mysql

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      32310/mysqld        


五、mysql密碼設置:

修改密碼的方式不少

方法一:

mysql_secure_installation

....

Set root password? [Y/n] y  #設置root用戶密碼

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.


Remove anonymous users? [Y/n] Y #刪除匿名用戶

 ... skipping.


Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] y #關閉root用戶遠程訪問

 ... Success!


By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.


Remove test database and access to it? [Y/n] y #刪除test庫

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] y #刷新權限表

 ... Success!


Cleaning up...


All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.


Thanks for using MySQL!


方法二:

mysql -uroot
mysql>delete from mysql.user where user='';
mysql>update mysql.user set password=password('密碼') where user='root';
mysql>drop database test;


六、關閉selinux:

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux


3、配置Cloudstack Manager

一、設置cloudstack數據庫

查看命令幫助:

cloudstack-setup-databases -h


cloudstack-setup-databases cloud:cloud@localhost \ #設置cloud帳號的密碼
 --deploy-as=root:<root_password> \ #輸入root帳號的密碼
 -e file \
 -m password \
 -k password \
 -i 10.1.6.30     #指定manager的服務器IP地址

輸出信息:

Mysql user name:cloud                                                           [ OK ]

Mysql user password:cloud                                                       [ OK ]

Mysql server ip:localhost                                                       [ OK ]

Mysql server port:3306                                                          [ OK ]

Mysql root user name:root                                                       [ OK ]

Mysql root user password:yau,.2012mn                                            [ OK ]

Using specified cluster management server node IP 10.1.6.20                     [ OK ]

Checking Cloud database files ...                                               [ OK ]

Checking local machine hostname ...                                             [ OK ]

Checking SELinux setup ...                                                      [ OK ]

Preparing /etc/cloudstack/management/db.properties                              [ OK ]

Applying /usr/share/cloudstack-management/setup/create-database.sql             [ OK ]

Applying /usr/share/cloudstack-management/setup/create-schema.sql               [ OK ]

Applying /usr/share/cloudstack-management/setup/create-database-premium.sql     [ OK ]

Applying /usr/share/cloudstack-management/setup/create-schema-premium.sql       [ OK ]

Applying /usr/share/cloudstack-management/setup/server-setup.sql                [ OK ]

Applying /usr/share/cloudstack-management/setup/templates.sql                   [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_db.sql                  [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_schema.sql              [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_multipart.sql           [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_index.sql               [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_multipart_alter.sql     [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_bucketpolicy.sql        [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_policy_alter.sql        [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_offering.sql            [ OK ]

Applying /usr/share/cloudstack-bridge/setup/cloudbridge_offering_alter.sql      [ OK ]

Processing encryption ...                                                       [ OK ]

Finalizing setup ...                                                            [ OK ]


CloudStack has successfully initialized database, you can check your database configuration in /etc/cloudstack/management/db.properties


二、啓動manager服務

cloudstack-setup-management

Starting to configure CloudStack Management Server:

Configure sudoers ...         [OK]

Configure Firewall ...        [OK]

Configure CloudStack Management Server ...[OK]

CloudStack Management Server setup is Done!


4、配置存儲(這裏使用NFS)

使用NFS保存primary和secondary storage,也可使用Ceph RBD, GlusterFS,iSCSI, and others.

一、在管理服務器上安裝NFS

yum -y install nfs-utils


二、建立導出目錄:(能夠每一個目錄單獨進行卷掛載)

mkdir -p /export/primary
mkdir -p /export/secondary


三、配置nfs(使用rw,async,no_root_squash,no_subtree_check)

# vim /etc/exports
/export *(rw,async,no_root_squash,no_subtree_check)


四、導出共享

exportfs -a


五、固定NFS服務端口:

# vim /etc/sysconfig/nfs
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
RQUOTAD_PORT=875
STATD_PORT=662
STATD_OUTGOING_PORT=2020


如開啓iptables,針對nfs須要開放端口:

# vi /etc/sysconfig/iptables
-A INPUT -s <NETWORK> -m state --state NEW -p udp --dport 111 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 111 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 2049 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 32803 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p udp --dport 32769 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 892 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p udp --dport 892 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 875 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p udp --dport 875 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p tcp --dport 662 -j ACCEPT
-A INPUT -s <NETWORK> -m state --state NEW -p udp --dport 662 -j ACCEPT


啓動iptables:

service iptables restart
service iptables save


六、在hypervisor host and Management Server上修改idmapd.conf,指定搜索域

# vim /etc/idmapd.conf
Domain = yaukb.com


七、重啓管理服務主機:

檢查NFS服務rpcbind服務運行

service rpcbind start
service nfs start
chkconfig nfs on
chkconfig rpcbind on


八、測試是否成功

a、登陸到hypervisor host

b、掛載測試

mkdir /mnt/secondary
mount -t nfs 10.1.6.20:/export/secondary /mnt/secondary


5、準備System VM模板(在Cloudstack Manager服務器上操做)

模板放在Secondary storage上:

使用命令cloud-install-sys-tmplt檢索和解壓模板文件,針對不一樣的hypervisor下載相應的vm模板


For XenServer:

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /mnt/secondary -u http://d21ifhcun6b1t2.cloudfront.net/templates/4.2/systemvmtemplate-2013-07-12-master-xen.vhd.bz2 -h xenserver -F


For vSphere:

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -/mnt/secondary -u  http://d21ifhcun6b1t2.cloudfront.net/templates/4.2/systemvmtemplate-4.2-vh7.ova -h vmware -F


For KVM:

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -/mnt/secondary -u http://d21ifhcun6b1t2.cloudfront.net/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2 -h kvm -F


For LXC:

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -/mnt/secondary -u http://d21ifhcun6b1t2.cloudfront.net/templates/acton/actonsystemvm-02062012.qcow2.bz2 -h lxc -F


因下載網速慢,能夠先提早下載到本地web服務器,而後同步到二級存儲:

以下載kvm模板:

cd /var/www/html/ && wget -c http://d21ifhcun6b1t2.cloudfront.net/templates/4.2/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2


而後使用命令cloud-install-sys-tmplt進行模板下載:

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -/mnt/secondary -u http://<http_server_ip>/systemvmtemplate-2013-06-12-master-kvm.qcow2.bz2 -h kvm -F


6、KVM Hypervisor配置

安裝步驟:

一、準備操做系統

二、安裝和配置libvirt

三、配置安全性策略(AppArmor and SELinux)

四、安裝和配置Agent


一、準備操做系統

要求在操做系統上運行Cloudstack Agent和KVM實例。

a、使用root用戶部署服務,檢查主機名是否符合FQDN格式:

hostname --fqdn


b、時間同步服務:

yum -y install ntp
service ntpd start
chkconfig ntpd on


二、安裝和配置Cloudstack Agent

Agent與Cloudstack管理服務通訊,管理主機上的實例


Yum源配置:

# vim /etc/yum.repos.d/cloudstack.repo
[cloudstack]
name=cloudstack
baseurl=http://cloudstack.apt-get.eu/rhel/4.2/
enabled=1
gpgcheck=0


安裝agent:

yum install cloudstack-agent


三、配置KVM客戶機的CPU Model:

默認爲QEMU Virtual CPU

# vim /etc/cloudstack/agent/agent.properties
guest.cpu.model=host-model #推薦模式


能夠配置參數以下:host-model適合不一樣主機之間遷移,有較好的性能

guest.cpu.mode=custom|host-model|host-passthrough

guest.cpu.model=from /usr/share/libvirt/cpu_map.xml(only valid when guest.cpu.mode=custom)


四、安裝和配置libvirt

Cloudstack使用libvirt管理虛擬機


# vim /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1 #監聽TCP
tcp_port = "16509"
auth_tcp = "none"
mdns_adv = 0 #關閉DNS廣播


# vim /etc/sysconfig/libvirtd
LIBVIRTD_ARGS="--listen"


修改VNC監聽到全部網卡:

# vim /etc/libvirt/qemu.conf  
vnc_listen = "0.0.0.0"


重啓libvirtd服務:

service libvirtd restart
chkconfig libvirtd on


五、配置安全策略

臨時關閉selinux:

setenforce 0


修改/etc/selinux/config永久生效:

sed -'s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux


六、配置網絡橋接

爲了轉發流量到實例,將至少須要兩個橋接:public和private,默認cloudstack使用cloudbr0和cloudbr1

這裏物理網卡名稱爲em1,使用linux橋接進行配置,將em1橋接到cloudbr0,建立一個無橋接的cloudbr1。

配置以下:

cd /etc/sysconfig/network-scripts/
cp ifcfg-em1 ifcfg-cloudbr0
cp ifcfg-em1 ifcfg-cloudbr1


#物理網卡配置,橋接到cloudbr0

#vim  ifcfg-em1 
DEVICE="em1"
BOOTPROTO="none"
DHCP_HOSTNAME="yau620.yaukb.com"
HWADDR="D4:BE:D9:93:D4:0E"
IPV6INIT="no"
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
UUID="b159e8c8-9915-4647-8c61-32ee83b066e0"
BRIDGE="cloudbr0"


公有網絡cloudbr0:

# cat ifcfg-cloudbr0
DEVICE=cloudbr0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPV6INIT=no
IPV6_AUTOCONF=no
IPADDR=10.1.6.20
NETMASK=255.255.255.0
GATEWAY=10.1.6.1


私有網絡cloudbr1:

# cat ifcfg-cloudbr1
DEVICE=cloudbr1
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPV6INIT=no
IPV6_AUTOCONF=no





來自爲知筆記(Wiz)

相關文章
相關標籤/搜索